Skip to content

Backport PR #24158 on branch v3.6.x (Fix Qt with PySide6 6.4.0) #24172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ jobs:
python-version: 3.8
extra-requirements: '-c requirements/testing/minver.txt'
pyqt5-ver: '==5.11.2 sip==5.0.0' # oldest versions with a Py3.8 wheel.
pyqt6-ver: '==6.1.0 PyQt6-Qt6==6.1.0'
pyside2-ver: '==5.14.0' # oldest version with working Py3.8 wheel.
pyside6-ver: '==6.0.0'
delete-font-cache: true
- os: ubuntu-20.04
python-version: 3.8
Expand Down Expand Up @@ -189,17 +192,17 @@ jobs:
echo 'PyQt5 is available' ||
echo 'PyQt5 is not available'
if [[ "${{ runner.os }}" != 'macOS' ]]; then
python -mpip install --upgrade pyside2 &&
python -mpip install --upgrade pyside2${{ matrix.pyside2-ver }} &&
python -c 'import PySide2.QtCore' &&
echo 'PySide2 is available' ||
echo 'PySide2 is not available'
fi
if [[ "${{ matrix.os }}" = ubuntu-20.04 ]]; then
python -mpip install --upgrade pyqt6 &&
python -mpip install --upgrade pyqt6${{ matrix.pyqt6-ver }} &&
python -c 'import PyQt6.QtCore' &&
echo 'PyQt6 is available' ||
echo 'PyQt6 is not available'
python -mpip install --upgrade pyside6 &&
python -mpip install --upgrade pyside6${{ matrix.pyside6-ver }} &&
python -c 'import PySide6.QtCore' &&
echo 'PySide6 is available' ||
echo 'PySide6 is not available'
Expand Down
18 changes: 13 additions & 5 deletions lib/matplotlib/backends/qt_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@


def _setup_pyqt5plus():
global QtCore, QtGui, QtWidgets, __version__, _isdeleted, _getSaveFileName
global QtCore, QtGui, QtWidgets, __version__
global _getSaveFileName, _isdeleted, _to_int

if QT_API == QT_API_PYQT6:
from PyQt6 import QtCore, QtGui, QtWidgets, sip
Expand All @@ -78,10 +79,15 @@ def _setup_pyqt5plus():
QtCore.Slot = QtCore.pyqtSlot
QtCore.Property = QtCore.pyqtProperty
_isdeleted = sip.isdeleted
_to_int = operator.attrgetter('value')
elif QT_API == QT_API_PYSIDE6:
from PySide6 import QtCore, QtGui, QtWidgets, __version__
import shiboken6
def _isdeleted(obj): return not shiboken6.isValid(obj)
if parse_version(__version__) >= parse_version('6.4'):
_to_int = operator.attrgetter('value')
else:
_to_int = int
elif QT_API == QT_API_PYQT5:
from PyQt5 import QtCore, QtGui, QtWidgets
import sip
Expand All @@ -90,11 +96,16 @@ def _isdeleted(obj): return not shiboken6.isValid(obj)
QtCore.Slot = QtCore.pyqtSlot
QtCore.Property = QtCore.pyqtProperty
_isdeleted = sip.isdeleted
_to_int = int
elif QT_API == QT_API_PYSIDE2:
from PySide2 import QtCore, QtGui, QtWidgets, __version__
import shiboken2
try:
from PySide2 import shiboken2
except ImportError:
import shiboken2
def _isdeleted(obj):
return not shiboken2.isValid(obj)
_to_int = int
else:
raise AssertionError(f"Unexpected QT_API: {QT_API}")
_getSaveFileName = QtWidgets.QFileDialog.getSaveFileName
Expand Down Expand Up @@ -141,9 +152,6 @@ def _isdeleted(obj):
# PyQt6 enum compat helpers.


_to_int = operator.attrgetter("value") if QT_API == "PyQt6" else int


@functools.lru_cache(None)
def _enum(name):
# foo.bar.Enum.Entry (PyQt6) <=> foo.bar.Entry (non-PyQt6).
Expand Down