Trying to get PyOpenGL working with PySide2
"J.L.M." <[email protected]> Wed, 29 Apr 2020 13:57:14 -0400
| Newsgroups | gmane.comp.python.opengl.user |
|---|---|
| Message-ID | <CAKq7qa4diD9gcKezD0wqm1H3KsKLtw-DkTSog5vrbHpa5VQjGQ@mail.gmail.com> |
--===============5575079038098984266==
Content-Type: multipart/alternative; boundary="0000000000004a990705a471ae1b"
--0000000000004a990705a471ae1b
Content-Type: text/plain; charset="UTF-8"
I am unsure how to make QT, PySide2, and PyOpenGL all work together. I
think I've found at least three different ways to create an OpenGL widget.
What I have below is a UI created in QT Designer and then converted into
Python, a subclass, and the main program. The problem I'm having is that
initalizeGL and paintGL are never getting called. resizeGL is getting
called.
from PySide2.QtCore import (QCoreApplication, QDate, QDateTime, QMetaObject,
QObject, QPoint, QRect, QSize, QTime, QUrl, Qt)
from PySide2.QtGui import (QBrush, QColor, QConicalGradient, QCursor, QFont,
QFontDatabase, QIcon, QKeySequence, QLinearGradient, QPalette, QPainter,
QPixmap, QRadialGradient)
from PySide2.QtWidgets import *
from canvas import Canvas
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
if not MainWindow.objectName():
MainWindow.setObjectName(u"MainWindow")
MainWindow.resize(984, 724)
self.centralwidget = QWidget(MainWindow)
self.centralwidget.setObjectName(u"centralwidget")
self.horizontalLayout = QHBoxLayout(self.centralwidget)
self.horizontalLayout.setObjectName(u"horizontalLayout")
self.verticalLayout = QVBoxLayout()
self.verticalLayout.setObjectName(u"verticalLayout")
self.horizontalLayout.addLayout(self.verticalLayout)
self.openGLWidget = Canvas(self.centralwidget)
self.openGLWidget.setObjectName(u"openGLWidget")
self.horizontalLayout.addWidget(self.openGLWidget)
self.horizontalLayout.setStretch(1, 1)
MainWindow.setCentralWidget(self.centralwidget)
-------------------------------------------------------------------------------------------------------------------------------------
from PySide2.QtWidgets import QOpenGLWidget
from OpenGL.GL import *
class Canvas(QOpenGLWidget):
def __init__(self, parent = None):
super().__init__(parent)
def initializeGl(self):
print("set clear color", flush=True)
initializeOpenGLFunctions()
glClearColor(1.0, 0.0, 0.0, 1.0)
def resizeGL(self, width, height):
print("resize", flush=True)
def paingGL(self):
print("paint", flush=True)
self.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
-----------------------------------------------------------------------------------------------------------------------------------------------------
import sys
from PySide2.QtWidgets import QApplication, QMainWindow
from PySide2.QtCore import QFile
from main_window import Ui_MainWindow
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
--0000000000004a990705a471ae1b
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>I am unsure how to make QT, PySide2, and PyOpenGL all=
work together. I think I've found at least three different ways to cre=
ate an OpenGL widget. What I have below is a UI created in QT Designer and =
then converted into Python, a subclass, and the main program. The problem I=
'm having is that initalizeGL and paintGL are never getting called. res=
izeGL is getting called.</div><div><br></div><div>from PySide2.QtCore impor=
t (QCoreApplication, QDate, QDateTime, QMetaObject,<br>=C2=A0 =C2=A0 QObjec=
t, QPoint, QRect, QSize, QTime, QUrl, Qt)<br>from PySide2.QtGui import (QBr=
ush, QColor, QConicalGradient, QCursor, QFont,<br>=C2=A0 =C2=A0 QFontDataba=
se, QIcon, QKeySequence, QLinearGradient, QPalette, QPainter,<br>=C2=A0 =C2=
=A0 QPixmap, QRadialGradient)<br>from PySide2.QtWidgets import *<br><br>fro=
m canvas import Canvas<br><br>class Ui_MainWindow(object):<br>=C2=A0 =C2=A0=
def setupUi(self, MainWindow):<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 if not MainW=
indow.objectName():<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 MainWindow=
.setObjectName(u"MainWindow")<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 Main=
Window.resize(984, 724)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.centralwidget =
=3D QWidget(MainWindow)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.centralwidget.s=
etObjectName(u"centralwidget")<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 sel=
f.horizontalLayout =3D QHBoxLayout(self.centralwidget)<br>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 self.horizontalLayout.setObjectName(u"horizontalLayout"=
;)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.verticalLayout =3D QVBoxLayout()<br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.verticalLayout.setObjectName(u"vertic=
alLayout")<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.horizontalLayout.addLay=
out(self.verticalLayout)<br><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.openGLWidg=
et =3D Canvas(self.centralwidget)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.openG=
LWidget.setObjectName(u"openGLWidget")<br><br>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 self.horizontalLayout.addWidget(self.openGLWidget)<br><br>=C2=A0=
=C2=A0 =C2=A0 =C2=A0 self.horizontalLayout.setStretch(1, 1)<br>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 MainWindow.setCentralWidget(self.centralwidget)</div><div=
><br></div><div><br></div><div>--------------------------------------------=
---------------------------------------------------------------------------=
--------------<br></div><div><br></div><div>from PySide2.QtWidgets import Q=
OpenGLWidget<br>from OpenGL.GL import *<br><br>class Canvas(QOpenGLWidget):=
<br>=C2=A0 =C2=A0 def __init__(self, parent =3D None):<br>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 super().__init__(parent)<br><br>=C2=A0 =C2=A0 def initializeGl(s=
elf):<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 print("set clear color", flu=
sh=3DTrue)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 initializeOpenGLFunctions()<br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 glClearColor(1.0, 0.0, 0.0, 1.0)<br><br>=C2=A0 =
=C2=A0 def resizeGL(self, width, height):<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 pr=
int("resize", flush=3DTrue)<br><br>=C2=A0 =C2=A0 def paingGL(self=
):<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 print("paint", flush=3DTrue)<br=
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DE=
PTH_BUFFER_BIT)</div><div><br></div><div>----------------------------------=
---------------------------------------------------------------------------=
----------------------------------------<br></div><div>import sys<br>from P=
ySide2.QtWidgets import QApplication, QMainWindow<br>from PySide2.QtCore im=
port QFile<br>from main_window import Ui_MainWindow<br><br>class MainWindow=
(QMainWindow):<br>=C2=A0 =C2=A0 def __init__(self):<br>=C2=A0 =C2=A0 =C2=A0=
=C2=A0 super().__init__()<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.ui =3D Ui_Ma=
inWindow()<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.ui.setupUi(self)<br><br>if _=
_name__ =3D=3D "__main__":<br>=C2=A0 =C2=A0 app =3D QApplication(=
sys.argv)<br><br>=C2=A0 =C2=A0 window =3D MainWindow()<br>=C2=A0 =C2=A0 win=
dow.show()<br><br>=C2=A0 =C2=A0 sys.exit(app.exec_())</div></div>
--0000000000004a990705a471ae1b--
--===============5575079038098984266==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
--===============5575079038098984266==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
PyOpenGL Homepage
http://pyopengl.sourceforge.net
_______________________________________________
PyOpenGL-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyopengl-users
--===============5575079038098984266==--