From ce8c3262f810290f3db4a06358c1e868412d86d7 Mon Sep 17 00:00:00 2001 From: pijyoi Date: Sun, 31 Jan 2021 00:59:29 +0800 Subject: [PATCH] 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 --- pyqtgraph/Qt.py | 11 ++--------- pyqtgraph/graphicsItems/PlotCurveItem.py | 15 ++++++--------- pyqtgraph/widgets/GraphicsView.py | 17 ++++++----------- 3 files changed, 14 insertions(+), 29 deletions(-) diff --git a/pyqtgraph/Qt.py b/pyqtgraph/Qt.py index 9709a482..83654c93 100644 --- a/pyqtgraph/Qt.py +++ b/pyqtgraph/Qt.py @@ -211,10 +211,6 @@ elif QT_LIB == PYQT5: from PyQt5 import QtSvg except ImportError as err: QtSvg = FailedImport(err) - try: - from PyQt5 import QtOpenGL - except ImportError as err: - QtOpenGL = FailedImport(err) try: from PyQt5 import QtTest QtTest.QTest.qWaitForWindowShown = QtTest.QTest.qWaitForWindowExposed @@ -249,10 +245,6 @@ elif QT_LIB == PYSIDE2: from PySide2 import QtSvg except ImportError as err: QtSvg = FailedImport(err) - try: - from PySide2 import QtOpenGL - except ImportError as err: - QtOpenGL = FailedImport(err) try: from PySide2 import QtTest 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 # recreate the Qt5 structure - QtWidgets.QOpenGLWidget = QtOpenGLWidgets.QOpenGLWidget + if not isinstance(QtOpenGLWidgets, FailedImport): + QtWidgets.QOpenGLWidget = QtOpenGLWidgets.QOpenGLWidget # Common to PySide, PySide2 and PySide6 diff --git a/pyqtgraph/graphicsItems/PlotCurveItem.py b/pyqtgraph/graphicsItems/PlotCurveItem.py index b56d3d4d..39003813 100644 --- a/pyqtgraph/graphicsItems/PlotCurveItem.py +++ b/pyqtgraph/graphicsItems/PlotCurveItem.py @@ -1,10 +1,6 @@ # -*- coding: utf-8 -*- -from ..Qt import QtGui, QtCore -try: - from ..Qt import QtOpenGL - HAVE_OPENGL = True -except: - HAVE_OPENGL = False +from ..Qt import QtCore, QtGui, QtWidgets +HAVE_OPENGL = hasattr(QtWidgets, 'QOpenGLWidget') import warnings import numpy as np @@ -483,9 +479,10 @@ class PlotCurveItem(GraphicsObject): if self.xData is None or len(self.xData) == 0: return - if HAVE_OPENGL and getConfigOption('enableExperimental') and isinstance(widget, QtOpenGL.QGLWidget): - self.paintGL(p, opt, widget) - return + if getConfigOption('enableExperimental'): + if HAVE_OPENGL and isinstance(widget, QtWidgets.QOpenGLWidget): + self.paintGL(p, opt, widget) + return x = None y = None diff --git a/pyqtgraph/widgets/GraphicsView.py b/pyqtgraph/widgets/GraphicsView.py index 4490d4de..6e93aa45 100644 --- a/pyqtgraph/widgets/GraphicsView.py +++ b/pyqtgraph/widgets/GraphicsView.py @@ -5,14 +5,7 @@ Copyright 2010 Luke Campagnola Distributed under MIT/X11 license. See license.txt for more information. """ -from ..Qt import QtCore, QtGui, QT_LIB - -try: - from ..Qt import QtOpenGL - HAVE_OPENGL = True -except ImportError: - HAVE_OPENGL = False - +from ..Qt import QtCore, QtGui, QtWidgets, QT_LIB from ..Point import Point import sys, os import warnings @@ -58,7 +51,7 @@ class GraphicsView(QtGui.QGraphicsView): useOpenGL If True, the GraphicsView will use OpenGL to do all of its rendering. This can improve performance on some systems, 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) background Set the background color of the GraphicsView. Accepts any single argument accepted by @@ -176,9 +169,11 @@ class GraphicsView(QtGui.QGraphicsView): def useOpenGL(self, b=True): if b: + HAVE_OPENGL = hasattr(QtWidgets, 'QOpenGLWidget') if not HAVE_OPENGL: - raise Exception("Requested to use OpenGL with QGraphicsView, but QtOpenGL module is not available.") - v = QtOpenGL.QGLWidget() + raise Exception("Requested to use OpenGL with QGraphicsView, but QOpenGLWidget is not available.") + + v = QtWidgets.QOpenGLWidget() else: v = QtGui.QWidget()