Skip to content

Commit 6241384

Browse files
authored
Merge pull request matplotlib#26052 from QuLogic/improve-qt
Improve Qt compatibility
2 parents 01cfd30 + 89fb6d4 commit 6241384

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

.github/workflows/tests.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,21 @@ jobs:
6262
python-version: 3.9
6363
extra-requirements: '-r requirements/testing/extra.txt'
6464
CFLAGS: "-fno-lto" # Ensure that disabling LTO works.
65+
# https://github.com/matplotlib/matplotlib/pull/26052#issuecomment-1574595954
66+
pyqt6-ver: '!=6.5.1'
6567
# https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-2346
6668
pyside6-ver: '!=6.5.1'
6769
- os: ubuntu-20.04
6870
python-version: '3.10'
6971
extra-requirements: '-r requirements/testing/extra.txt'
72+
# https://github.com/matplotlib/matplotlib/pull/26052#issuecomment-1574595954
73+
pyqt6-ver: '!=6.5.1'
7074
# https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-2346
7175
pyside6-ver: '!=6.5.1'
7276
- os: ubuntu-20.04
7377
python-version: '3.11'
78+
# https://github.com/matplotlib/matplotlib/pull/26052#issuecomment-1574595954
79+
pyqt6-ver: '!=6.5.1'
7480
# https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-2346
7581
pyside6-ver: '!=6.5.1'
7682
- os: macos-latest

lib/matplotlib/backends/backend_qt.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,10 @@ def _create_qApp():
106106
# of Qt is not instantiated in the process
107107
if QT_API in {'PyQt6', 'PySide6'}:
108108
other_bindings = ('PyQt5', 'PySide2')
109+
qt_version = 6
109110
elif QT_API in {'PyQt5', 'PySide2'}:
110111
other_bindings = ('PyQt6', 'PySide6')
112+
qt_version = 5
111113
else:
112114
raise RuntimeError("Should never be here")
113115

@@ -123,11 +125,11 @@ def _create_qApp():
123125
'versions may not work as expected.'
124126
)
125127
break
126-
try:
127-
QtWidgets.QApplication.setAttribute(
128-
QtCore.Qt.AA_EnableHighDpiScaling)
129-
except AttributeError: # Only for Qt>=5.6, <6.
130-
pass
128+
if qt_version == 5:
129+
try:
130+
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
131+
except AttributeError: # Only for Qt>=5.6, <6.
132+
pass
131133
try:
132134
QtWidgets.QApplication.setHighDpiScaleFactorRoundingPolicy(
133135
QtCore.Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
@@ -141,10 +143,8 @@ def _create_qApp():
141143
app.lastWindowClosed.connect(app.quit)
142144
cbook._setup_new_guiapp()
143145

144-
try:
145-
app.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps) # Only for Qt<6.
146-
except AttributeError:
147-
pass
146+
if qt_version == 5:
147+
app.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps)
148148

149149
return app
150150

@@ -522,9 +522,6 @@ class FigureManagerQT(FigureManagerBase):
522522
def __init__(self, canvas, num):
523523
self.window = MainWindow()
524524
super().__init__(canvas, num)
525-
self.window.closing.connect(
526-
# The lambda prevents the event from being immediately gc'd.
527-
lambda: CloseEvent("close_event", self.canvas)._process())
528525
self.window.closing.connect(self._widgetclosed)
529526

530527
if sys.platform != "darwin":
@@ -569,6 +566,7 @@ def full_screen_toggle(self):
569566
self.window.showFullScreen()
570567

571568
def _widgetclosed(self):
569+
CloseEvent("close_event", self.canvas)._process()
572570
if self.window._destroying:
573571
return
574572
self.window._destroying = True

0 commit comments

Comments
 (0)