File tree Expand file tree Collapse file tree 2 files changed +47
-5
lines changed Expand file tree Collapse file tree 2 files changed +47
-5
lines changed Original file line number Diff line number Diff line change
1
+ from PyQt5 .QtWidgets import QApplication , QMainWindow
2
+ from PyQt5 .QtOpenGL import QGLWidget
3
+ from PyQt5 .QtCore import pyqtSlot
4
+ import sys
5
+
6
+ class MyOpenGLWidget (QGLWidget ):
7
+ def __init__ (self , parent = None ):
8
+ super ().__init__ (parent )
9
+ # Connect the aboutToBeDestroyed signal to your cleanup slot
10
+ self .aboutToBeDestroyed .connect (self .cleanupGL )
11
+
12
+ @pyqtSlot ()
13
+ def cleanupGL (self ):
14
+ # This will be called just before the GL context is destroyed
15
+ print ("OpenGL context is about to be destroyed. Clean up GPU resources here." )
16
+
17
+ def initializeGL (self ):
18
+ print ("initializeGL: OpenGL context created." )
19
+
20
+ def resizeGL (self , w , h ):
21
+ print (f"resizeGL: { w } x{ h } " )
22
+
23
+ def paintGL (self ):
24
+ pass
25
+
26
+ class MainWindow (QMainWindow ):
27
+ def __init__ (self ):
28
+ super ().__init__ ()
29
+ self .setCentralWidget (MyOpenGLWidget (self ))
30
+
31
+ def main ():
32
+ app = QApplication (sys .argv )
33
+ window = MainWindow ()
34
+ window .show ()
35
+ sys .exit (app .exec ())
36
+
37
+ if __name__ == "__main__" :
38
+ main ()
Original file line number Diff line number Diff line change @@ -7,12 +7,16 @@ class MyOpenGLWidget(QOpenGLWidget):
7
7
def __init__ (self , parent = None ):
8
8
super ().__init__ (parent )
9
9
# Connect the aboutToBeDestroyed signal to your cleanup slot
10
- self .aboutToBeDestroyed .connect (self .cleanupGL )
10
+ # self.aboutToBeDestroyed.connect(self.cleanupGL)
11
11
12
- @pyqtSlot ()
13
- def cleanupGL (self ):
14
- # This will be called just before the GL context is destroyed
15
- print ("OpenGL context is about to be destroyed. Clean up GPU resources here." )
12
+ #@pyqtSlot()
13
+ #def cleanupGL(self):
14
+ # # This will be called just before the GL context is destroyed
15
+ # print("OpenGL context is about to be destroyed. Clean up GPU resources here.")
16
+
17
+ def closeEvent (self , event ):
18
+ print ("Widget is about to be destroyed" )
19
+ super ().closeEvent (event )
16
20
17
21
def initializeGL (self ):
18
22
print ("initializeGL: OpenGL context created." )
You can’t perform that action at this time.
0 commit comments