[PyOpenGL-Users] Trying to get PyOpenGL working with PySide2
Brought to you by:
mcfletch
|
From: J.L.M. <jl...@gm...> - 2020-04-29 17:57:34
|
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_())
|