some fixes for PySide6 future compatibility#1495
Conversation
| if hasattr(g, 'setStops'): | ||
| g.setStops(list(stops)) | ||
| else: | ||
| # PySide6 has a missing setStops binding |
There was a problem hiding this comment.
is this documented anywhere? the method is referenced in the docs:
There was a problem hiding this comment.
It's present in Qt6 but the binding is missing in PySide6. It could just be an unintended omission.
https://doc.qt.io/qtforpython/PySide6/QtGui/QGradient.html
In any case, hasattr(QtGui.QLinearGradient, 'setStops') is True for PySide2 but False for PySide6.
|
Hi @pijyoi thanks for this PR and tackling this issue! I'm curious about the changes in all the templates files, for Qt6, we should likely be generating new template files, not modifying the existing ones. If it would help, I can create new template files and add them to this PR, since they can be a bit annoying to generate. |
The intention for these fixes is only to get the code "future"-ready. i.e. Minor fixes to convert usage of deprecated and obsolete APIs. In this case, setWeight() in PySide6 no longer takes an integer, and in any case, the enum value 75 was no longer correct. Since setBold(True) already does the same thing as setWeight(Bold), removing the "weight" property altogether was the simpler solution.
I did try re-generating a template using pyside2-uic, but this resulted in numerous differences from the existing file, which I thought would clutter the git history. In any case, the manual edits are localized to a single commit. I noticed that examples/VideoTemplate_pyside2.py, compared to the files for the other bindings, imports RawImageGLWidget unconditionally, such that the example will fail to run if pyopengl isn't installed. Any ideas why? |
|
On my local machine, I have manually "generated" all the *_pyside6.py files by making a copy of the corresponding *_pyside2.py files and changing PySide2 to PySide6. Almost all the examples are able to launch and display something with PySide6
MatplotlibWidget.py was not updated. ScatterPlotItem.py seems to have a PySide2-specific codepath: |
|
Hi @pijyoi would you like to hop on our slack (so we can communicate outside of issue trackers)? Is interested, feel free to email me, the email is in my github profile. |
|
Hi @j9ac9k , I am good to remain on github for now. |
aa706ac to
b4e11fb
Compare
|
TIL about
I've manually made small changes to these template files only to regret it. I've been tempted to migrate the creation of these template files to be part of the CI process ....but for the time being I decided that is more trouble than its worth. The reason for this change is due to a complete reimplementation of Should this PR also attempt to get PyQt6 compatibility as well now that its' on PyPi? |
e497713 to
fe526ca
Compare
I have tried to make the changes in this PR to be less PySide6 specific. I attempted to add PyQt6 support but it appears that it is going to require more effort than PySide6. Many enums values are not in their old places. |
|
For example, for the enum TransformationType.TxRotate, in PySide2, PySide6 and PyQt5, it can be accessed as
In PyQt6, it is only accessible from the latter. https://riverbankcomputing.com/pipermail/pyqt/2020-December/043446.html |
|
Thanks for looking into this @pijyoi I'll have to figure out how to redo the matrix of test dependencies defined here: https://github.com/pyqtgraph/pyqtgraph/blob/master/.github/workflows/main.yml#L11-L24 such that PySide6 is added to the test suite. If you have any suggestions, I would say feel free to modify the python-3.9 config such that it uses Qt6. Also, I'd be curious to get your take on incorporating QtPy (I know they don't currently support Qt6 but they will at some point). |
convert QTreeWidget.setFirstItemColumnSpanned(item, True) to item.setFirstColumnSpanned(True) the former is deprecated since Qt 5.15.2 and removed in Qt 6.
the former is no longer present in Qt 6 as an alias
QFont.setBold(True) calls QFont.setWeight(QFont.Weight.Bold) in Qt 5, QFont.Weight.Bold == 75 in Qt 6, QFont.Weight.Bold == 700 in PySide6, QFont.setWeight() no longer accepts an integer value.
the former is obsolete in 5.15 and is removed in 6.0
also update for PySide2.QImage to take in ndarray directly.
the "try, except" could be dropped if we drop Qt4 support. however, primaryScreen() may not be the right screen.
Perhaps? It's easy enough to add |
|
Sorry for spamming some CI change commits to your PR, feel free to rebase/squash those commits together. Looks like Qt6 effectively needs ubuntu 20.04, github actions was supposed to migrate to that for A couple of notes:
For the image tests, we probably want to add |
|
Is it possible to run the tests directly from the development directory without installing it? I can run those under the tests subdir $ pytest pyqtgraph/tests/test_reload.pybut those under the graphicsItems subdir will complain about "No module named pyqtgraph" $ pytest pyqtgraph/graphicsItems/tests/test_ROI.py |
QDesktopWidget is deprecated in Qt5 and removed in Qt6
documentation for Qt 4.8 and Qt 5.12 have advised to "Use AdjustToContents or AdjustToContentsOnFirstShow instead" documentation in Qt 5.15 no longer shows AdjustToMinimumContentsLength.
Install package for libopengl.so Mandate the use of ubuntu 20.04
test_ImageView() - PySide6 fails the same as PySide2 test_PlotWidget() and test_GraphicsWindow() - PySide6 succeeds. - PySide2 also succeeds. (at least on Linux and on version 5.15.2)
https://bugreports.qt.io/plugins/servlet/mobile#issue/PYSIDE-1461 |
In the case of The other directories don't attempt to do the same, and assume the pyqtgraph module is installed. Is there a reason you're trying to run tests w/o installing the library? When making a bunch of changes, I often install pyqtgraph in editable mode |
Oh, I didn't know about "pip install -e" |
Highly recommend using editable installs as it best simulates an end-user interaction with the library. There is one difference I've found with editable installs vs. non-editable pip installs; and that is accessing the example app can be different. |
|
@pijyoi I think I know how to fix that git error that comes up on the macOS builds, I'm going to try and get the fix merged shortly... if CI here comes back all green after that, this PR ready to merge? |
Yes, ready for merging. |
Sorry, forgot one last requested change, can you update the Qt Bindings test matrix in As well as the supported Qt binding up higher. That's the last change I got... |
|
@pijyoi do you have strong opinions if this should be squashed or merged with all the commits? |
|
Well, at the very least, the commit that adds the generated files should be separate. But otherwise, I have already tried to squash related things together. I try to keep each commit to only perform one type of fix, so that it can be cherry-picked or reverted. i.e I have a mild preference to keep the commits separate. |
Good enough for me. |
|
Woot |
fixup some code so that it will be future-compatible with PySide6