switch to use of QOpenGLWidget in GraphicsView.py (#1525)

* switch to use of QOpenGLWidget in GraphicsView.py

experimental plotting in PlotCurveItem gets broken by this. so we allow
Qt5 users to opt back to using QGLWidget with the enableExperimental
option.

* allow Qt6 users to turn on enableExperimental

to more easily allow users to see the broken-ness.

* drop QGLWidget, use only QOpenGLWidget
This commit is contained in:
pijyoi 2021-01-31 00:59:29 +08:00 committed by GitHub
parent e9eb8d50b6
commit ce8c3262f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 29 deletions

View File

@ -211,10 +211,6 @@ elif QT_LIB == PYQT5:
from PyQt5 import QtSvg from PyQt5 import QtSvg
except ImportError as err: except ImportError as err:
QtSvg = FailedImport(err) QtSvg = FailedImport(err)
try:
from PyQt5 import QtOpenGL
except ImportError as err:
QtOpenGL = FailedImport(err)
try: try:
from PyQt5 import QtTest from PyQt5 import QtTest
QtTest.QTest.qWaitForWindowShown = QtTest.QTest.qWaitForWindowExposed QtTest.QTest.qWaitForWindowShown = QtTest.QTest.qWaitForWindowExposed
@ -249,10 +245,6 @@ elif QT_LIB == PYSIDE2:
from PySide2 import QtSvg from PySide2 import QtSvg
except ImportError as err: except ImportError as err:
QtSvg = FailedImport(err) QtSvg = FailedImport(err)
try:
from PySide2 import QtOpenGL
except ImportError as err:
QtOpenGL = FailedImport(err)
try: try:
from PySide2 import QtTest from PySide2 import QtTest
QtTest.QTest.qWaitForWindowShown = QtTest.QTest.qWaitForWindowExposed QtTest.QTest.qWaitForWindowShown = QtTest.QTest.qWaitForWindowExposed
@ -354,7 +346,8 @@ if QT_LIB in [PYQT6, PYSIDE6]:
# We're using Qt6 which has a different structure so we're going to use a shim to # We're using Qt6 which has a different structure so we're going to use a shim to
# recreate the Qt5 structure # recreate the Qt5 structure
QtWidgets.QOpenGLWidget = QtOpenGLWidgets.QOpenGLWidget if not isinstance(QtOpenGLWidgets, FailedImport):
QtWidgets.QOpenGLWidget = QtOpenGLWidgets.QOpenGLWidget
# Common to PySide, PySide2 and PySide6 # Common to PySide, PySide2 and PySide6

View File

@ -1,10 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from ..Qt import QtGui, QtCore from ..Qt import QtCore, QtGui, QtWidgets
try: HAVE_OPENGL = hasattr(QtWidgets, 'QOpenGLWidget')
from ..Qt import QtOpenGL
HAVE_OPENGL = True
except:
HAVE_OPENGL = False
import warnings import warnings
import numpy as np import numpy as np
@ -483,9 +479,10 @@ class PlotCurveItem(GraphicsObject):
if self.xData is None or len(self.xData) == 0: if self.xData is None or len(self.xData) == 0:
return return
if HAVE_OPENGL and getConfigOption('enableExperimental') and isinstance(widget, QtOpenGL.QGLWidget): if getConfigOption('enableExperimental'):
self.paintGL(p, opt, widget) if HAVE_OPENGL and isinstance(widget, QtWidgets.QOpenGLWidget):
return self.paintGL(p, opt, widget)
return
x = None x = None
y = None y = None

View File

@ -5,14 +5,7 @@ Copyright 2010 Luke Campagnola
Distributed under MIT/X11 license. See license.txt for more information. Distributed under MIT/X11 license. See license.txt for more information.
""" """
from ..Qt import QtCore, QtGui, QT_LIB from ..Qt import QtCore, QtGui, QtWidgets, QT_LIB
try:
from ..Qt import QtOpenGL
HAVE_OPENGL = True
except ImportError:
HAVE_OPENGL = False
from ..Point import Point from ..Point import Point
import sys, os import sys, os
import warnings import warnings
@ -58,7 +51,7 @@ class GraphicsView(QtGui.QGraphicsView):
useOpenGL If True, the GraphicsView will use OpenGL to do all of its useOpenGL If True, the GraphicsView will use OpenGL to do all of its
rendering. This can improve performance on some systems, rendering. This can improve performance on some systems,
but may also introduce bugs (the combination of but may also introduce bugs (the combination of
QGraphicsView and QGLWidget is still an 'experimental' QGraphicsView and QOpenGLWidget is still an 'experimental'
feature of Qt) feature of Qt)
background Set the background color of the GraphicsView. Accepts any background Set the background color of the GraphicsView. Accepts any
single argument accepted by single argument accepted by
@ -176,9 +169,11 @@ class GraphicsView(QtGui.QGraphicsView):
def useOpenGL(self, b=True): def useOpenGL(self, b=True):
if b: if b:
HAVE_OPENGL = hasattr(QtWidgets, 'QOpenGLWidget')
if not HAVE_OPENGL: if not HAVE_OPENGL:
raise Exception("Requested to use OpenGL with QGraphicsView, but QtOpenGL module is not available.") raise Exception("Requested to use OpenGL with QGraphicsView, but QOpenGLWidget is not available.")
v = QtOpenGL.QGLWidget()
v = QtWidgets.QOpenGLWidget()
else: else:
v = QtGui.QWidget() v = QtGui.QWidget()