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
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,6 +346,7 @@ 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
if not isinstance(QtOpenGLWidgets, FailedImport):
QtWidgets.QOpenGLWidget = QtOpenGLWidgets.QOpenGLWidget

View File

@ -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,7 +479,8 @@ 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):
if getConfigOption('enableExperimental'):
if HAVE_OPENGL and isinstance(widget, QtWidgets.QOpenGLWidget):
self.paintGL(p, opt, widget)
return

View File

@ -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()