Skip to content

switch to use of QOpenGLWidget in GraphicsView.py#1525

Merged
j9ac9k merged 3 commits intopyqtgraph:masterfrom
pijyoi:gfxview_opengl
Jan 30, 2021
Merged

switch to use of QOpenGLWidget in GraphicsView.py#1525
j9ac9k merged 3 commits intopyqtgraph:masterfrom
pijyoi:gfxview_opengl

Conversation

@pijyoi
Copy link
Copy Markdown
Contributor

@pijyoi pijyoi commented Jan 30, 2021

For Qt5, this switches from use of legacy QGLWidget to QOpenGLWidget.
For Qt6, this enables the option of using OpenGL, also using QOpenGLWidget.

Experimental plotting in PlotCurveItem gets broken by this switch and I do not know how to fix it, so we allow Qt5 users to opt back to using QGLWidget with the enableExperimental option.

There is some discussion here about issues with switching from QGLWidget to QOpenGLWidget when using them as a viewport.
https://stackoverflow.com/questions/31658176/using-qopenglwidget-with-qgraphicsview-viewport-not-updating

experimental plotting in PlotCurveItem gets broken by this. so we allow
Qt5 users to opt back to using QGLWidget with the enableExperimental
option.
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jan 30, 2021

Do you think it is worth attempting to try and get QOpenGLWidget to work with PlotCurveItem or do you think that's a lost cause until there is some upstream fix?

Looking at the Qt Bucktracker, I have found

I didn't notice any workarounds in those issues unfortunately.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jan 30, 2021

On PyQt6, after removing the enableExperimental check in PlotCurveItem.paint, examples/MouseSelection.py works for me (with adding pg.setConfigOptions(useOpenGL=True) at the top of the file).

How was PlotCurveItem broken for you?

EDIT: wait, I messed something up, investigating further...

EDIT2: Got it working with a ridiculous if-check in PlotCurveItem.paint

        if HAVE_OPENGL and \
            (
                (
                    getConfigOption('enableExperimental') and \
                    hasattr(QtOpenGL, 'QGLWidget') and \
                    isinstance(widget, QtOpenGL.QGLWidget)
                ) or \
                (
                    hasattr(QtWidgets, 'QOpenGLWidget') and \
                    isinstance(widget, QtWidgets.QOpenGLWidget)
                )
            ):
            self.paintGL(p, opt, widget)
            return

with PyQt6 on macOS, this block of code is run (enableExperimental has to be set to False).

Given this is the only place that enableExperimental is used, should we just get rid of that option (and if we get rid of that option, should we ditch every reference of QGLWidget instead of QOpenGLWidget?)

EDIT3:

I also had to add this to my PyQt6 block:

    try:
        from PyQt6 import QtOpenGL
    except ImportError as err:
        QtOpenGL = FailedImport(err)

I'm about to try with PySide6

EDIT4: Got it working with PySide6 with the same changes as I made for PyQt6.

to more easily allow users to see the broken-ness.
@pijyoi
Copy link
Copy Markdown
Contributor Author

pijyoi commented Jan 30, 2021

I get the following on Windows 10 when using QOpenGLWidget on either Qt5 and Qt6. So maybe it is OS dependent.
qt6_opengl_mouse_selection

I didn't import QtOpenGL in Qt.py for Qt6 because it is not used. So, in the previous code, Qt6 users would get a QtOpenGL import failure and thus have HAVE_OPENGL = False.

I have modified the code to allow Qt6 users to turn on enableExperimental. After all, it is an opt-in.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jan 30, 2021 via email

@pijyoi
Copy link
Copy Markdown
Contributor Author

pijyoi commented Jan 30, 2021

I just tried it on Linux and it seems to work.

@pijyoi
Copy link
Copy Markdown
Contributor Author

pijyoi commented Jan 30, 2021

Given this is the only place that enableExperimental is used, should we just get rid of that option (and if we get rid of that option, should we ditch every reference of QGLWidget instead of QOpenGLWidget?)

As a user, I could want to enable useOpenGL without enabling enableExperimental. I would like to ditch QGLWidget even if that breaks Windows. Users affected are those who had opted in to enableExperimental.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jan 30, 2021

I get the same problem on windows with PyQt5 5.15 and PyQt6.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jan 30, 2021

This PR LGTM, code is much cleaner, no more ambiguity between QGLWidget vs. QOpenGLWidget... Thanks so much for doing this @pijyoi !

@j9ac9k j9ac9k merged commit ce8c326 into pyqtgraph:master Jan 30, 2021
@pijyoi
Copy link
Copy Markdown
Contributor Author

pijyoi commented Jan 31, 2021

Maybe the following code might give a clue to someone knowledgeable with Windows OpenGL.
The data gets drawn if the x and y coords lie between [-1, 1]. It's not drawn within the axes either.

import numpy as np
import pyqtgraph as pg
pg.setConfigOption('useOpenGL', True)
pg.setConfigOption('enableExperimental', True)

app = pg.mkQApp()
win = pg.plot()

xxx = np.linspace(-1, 1, 1000)
yyy = np.sin(2*np.pi*3*xxx)
curve = pg.PlotCurveItem(x=xxx, y=yyy, pen='g', clickable=True)
win.addItem(curve)
              
app.exec_()

Capture

@pijyoi pijyoi deleted the gfxview_opengl branch January 31, 2021 02:08
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jan 31, 2021

@pijyoi do you happen to have a hidpi display or use fractional scaling (150% or 175%?) by chance?

@pijyoi
Copy link
Copy Markdown
Contributor Author

pijyoi commented Jan 31, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants