Skip to content

Commit 36ab8e1

Browse files
committed
Use QOpenGLWidget if available in late Qt5 (5.4 onwards)
Both QOpenGLWidget and QGLWidget are available in late Qt5, but to be imported from different modules. Realized slight mistake after the C++ porting. Now the code work with both.
1 parent 2879c0b commit 36ab8e1

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

SkiaPyQt5Example.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import sys
22
from PyQt5 import QtWidgets, QtCore, QtGui
33
from PyQt5.QtWidgets import QApplication, QMainWindow
4-
from PyQt5.QtOpenGL import QGLWidget
4+
5+
# QOpenGLWidget is available from Qt 5.4 onward, and preferred.
6+
from PyQt5.QtCore import QT_VERSION
7+
if (QT_VERSION >= 0x050400):
8+
from PyQt5.QtWidgets import QOpenGLWidget
9+
else:
10+
from PyQt5.QtOpenGL import QGLWidget as QOpenGLWidget
11+
512
import skia
613
import OpenGL.GL as gl
714

8-
class SkiaGLWidget(QGLWidget):
15+
class SkiaGLWidget(QOpenGLWidget):
916
def __init__(self, parent=None):
1017
super().__init__(parent)
1118
self.setMouseTracking(True)

0 commit comments

Comments
 (0)