diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9f137b720937..ba33ad760859 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -62,15 +62,21 @@ jobs: python-version: 3.9 extra-requirements: '-r requirements/testing/extra.txt' CFLAGS: "-fno-lto" # Ensure that disabling LTO works. + # https://github.com/matplotlib/matplotlib/pull/26052#issuecomment-1574595954 + pyqt6-ver: '!=6.5.1' # https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-2346 pyside6-ver: '!=6.5.1' - os: ubuntu-20.04 python-version: '3.10' extra-requirements: '-r requirements/testing/extra.txt' + # https://github.com/matplotlib/matplotlib/pull/26052#issuecomment-1574595954 + pyqt6-ver: '!=6.5.1' # https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-2346 pyside6-ver: '!=6.5.1' - os: ubuntu-20.04 python-version: '3.11' + # https://github.com/matplotlib/matplotlib/pull/26052#issuecomment-1574595954 + pyqt6-ver: '!=6.5.1' # https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-2346 pyside6-ver: '!=6.5.1' - os: macos-latest diff --git a/lib/matplotlib/backends/backend_qt.py b/lib/matplotlib/backends/backend_qt.py index faeb0d6bb700..f4b281bdd05c 100644 --- a/lib/matplotlib/backends/backend_qt.py +++ b/lib/matplotlib/backends/backend_qt.py @@ -106,8 +106,10 @@ def _create_qApp(): # of Qt is not instantiated in the process if QT_API in {'PyQt6', 'PySide6'}: other_bindings = ('PyQt5', 'PySide2') + qt_version = 6 elif QT_API in {'PyQt5', 'PySide2'}: other_bindings = ('PyQt6', 'PySide6') + qt_version = 5 else: raise RuntimeError("Should never be here") @@ -123,11 +125,11 @@ def _create_qApp(): 'versions may not work as expected.' ) break - try: - QtWidgets.QApplication.setAttribute( - QtCore.Qt.AA_EnableHighDpiScaling) - except AttributeError: # Only for Qt>=5.6, <6. - pass + if qt_version == 5: + try: + QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling) + except AttributeError: # Only for Qt>=5.6, <6. + pass try: QtWidgets.QApplication.setHighDpiScaleFactorRoundingPolicy( QtCore.Qt.HighDpiScaleFactorRoundingPolicy.PassThrough) @@ -141,10 +143,8 @@ def _create_qApp(): app.lastWindowClosed.connect(app.quit) cbook._setup_new_guiapp() - try: - app.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps) # Only for Qt<6. - except AttributeError: - pass + if qt_version == 5: + app.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps) return app @@ -522,9 +522,6 @@ class FigureManagerQT(FigureManagerBase): def __init__(self, canvas, num): self.window = MainWindow() super().__init__(canvas, num) - self.window.closing.connect( - # The lambda prevents the event from being immediately gc'd. - lambda: CloseEvent("close_event", self.canvas)._process()) self.window.closing.connect(self._widgetclosed) if sys.platform != "darwin": @@ -569,6 +566,7 @@ def full_screen_toggle(self): self.window.showFullScreen() def _widgetclosed(self): + CloseEvent("close_event", self.canvas)._process() if self.window._destroying: return self.window._destroying = True