Ndeh Ngwa
Ndeh Ngwa

Reputation: 31

OpenGL Causes PySide6/PyQt6 Application to Reload itself

When adding (at runtime) a new widget that carries any OpenGl component or is in itself an OpenGL widget(for example QOpenGLWidget), the application 'reloads' itself. Only after the 'reload' does it show the OpenGL widget. Even though the application 'reloads' it appears to maintain the previous application state as far as I have noticed.

Problems caused/noticed

Sample Example

The provided code example uses pyqtgraphto render 3d objects.

from PyQt6.QtWidgets import QApplication, QVBoxLayout, QPushButton, QLabel, QMainWindow, QWidget
import sys 
import pyqtgraph.opengl as gl

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        w = QWidget()
        self.wLayout = QVBoxLayout()
        self.setWindowTitle("OpenGL widget Error")
        self.state = QLabel("Before adding open gl, window effect intact")
        self.addWButton = QPushButton("add 3d widget")
        self.addWButton.clicked.connect(self.add3DWidget)
        self.wLayout.addWidget(self.state)
        self.wLayout.addWidget(self.addWButton)
        w.setLayout(self.wLayout)
        self.setCentralWidget(w)

    def add3DWidget(self):
        w3d = gl.GLViewWidget()
        self.wLayout.addWidget(w3d)
        self.state.setText("After adding opengl widget, application reloads")


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec())

My Envronment

This 'reload' happens when using PySide6 or PyQt6. When tested on PyQt5, the reload does not occur. I have not tested with other versions of PySide or PyQt.

Why does this happen and how can it be prevent it from happening?

Assitance will be very much appreciated.

Edit as adviced by @musicamante

Here is a screencapture for pyqt5 and pyqt6 respectively.

Window behaviour with pyqt5

Window behaviour with pyqt5

Window behaviour with pyqt6

Window behaviour with pyqt6

Upvotes: 2

Views: 290

Answers (0)

Related Questions