Skip to content

Commit 5958e32

Browse files
authored
Merge pull request #26055 from meeseeksmachine/auto-backport-of-pr-26052-on-v3.7.x
Backport PR #26052 on branch v3.7.x (Improve Qt compatibility)
2 parents e5c050e + 1e8ebda commit 5958e32

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

.github/workflows/tests.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,28 @@ jobs:
4848
python-version: 3.8
4949
extra-requirements: '-r requirements/testing/extra.txt'
5050
CFLAGS: "-fno-lto" # Ensure that disabling LTO works.
51+
# https://github.com/matplotlib/matplotlib/pull/26052#issuecomment-1574595954
52+
pyqt6-ver: '!=6.5.1'
5153
# https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-2346
5254
pyside6-ver: '!=6.5.1'
5355
- os: ubuntu-20.04
5456
python-version: 3.9
5557
extra-requirements: '-r requirements/testing/extra.txt'
58+
# https://github.com/matplotlib/matplotlib/pull/26052#issuecomment-1574595954
59+
pyqt6-ver: '!=6.5.1'
5660
# https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-2346
5761
pyside6-ver: '!=6.5.1'
5862
- os: ubuntu-20.04
5963
python-version: '3.10'
6064
extra-requirements: '-r requirements/testing/extra.txt'
65+
# https://github.com/matplotlib/matplotlib/pull/26052#issuecomment-1574595954
66+
pyqt6-ver: '!=6.5.1'
6167
# https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-2346
6268
pyside6-ver: '!=6.5.1'
6369
- os: ubuntu-20.04
6470
python-version: '3.11'
71+
# https://github.com/matplotlib/matplotlib/pull/26052#issuecomment-1574595954
72+
pyqt6-ver: '!=6.5.1'
6573
# https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-2346
6674
pyside6-ver: '!=6.5.1'
6775
- os: macos-latest

lib/matplotlib/backends/backend_qt.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,10 @@ def _create_qApp():
113113
# of Qt is not instantiated in the process
114114
if QT_API in {'PyQt6', 'PySide6'}:
115115
other_bindings = ('PyQt5', 'PySide2')
116+
qt_version = 6
116117
elif QT_API in {'PyQt5', 'PySide2'}:
117118
other_bindings = ('PyQt6', 'PySide6')
119+
qt_version = 5
118120
else:
119121
raise RuntimeError("Should never be here")
120122

@@ -130,11 +132,11 @@ def _create_qApp():
130132
'versions may not work as expected.'
131133
)
132134
break
133-
try:
134-
QtWidgets.QApplication.setAttribute(
135-
QtCore.Qt.AA_EnableHighDpiScaling)
136-
except AttributeError: # Only for Qt>=5.6, <6.
137-
pass
135+
if qt_version == 5:
136+
try:
137+
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
138+
except AttributeError: # Only for Qt>=5.6, <6.
139+
pass
138140
try:
139141
QtWidgets.QApplication.setHighDpiScaleFactorRoundingPolicy(
140142
QtCore.Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
@@ -148,10 +150,8 @@ def _create_qApp():
148150
app.lastWindowClosed.connect(app.quit)
149151
cbook._setup_new_guiapp()
150152

151-
try:
152-
app.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps) # Only for Qt<6.
153-
except AttributeError:
154-
pass
153+
if qt_version == 5:
154+
app.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps)
155155

156156
return app
157157

@@ -529,9 +529,6 @@ class FigureManagerQT(FigureManagerBase):
529529
def __init__(self, canvas, num):
530530
self.window = MainWindow()
531531
super().__init__(canvas, num)
532-
self.window.closing.connect(
533-
# The lambda prevents the event from being immediately gc'd.
534-
lambda: CloseEvent("close_event", self.canvas)._process())
535532
self.window.closing.connect(self._widgetclosed)
536533

537534
if sys.platform != "darwin":
@@ -576,6 +573,7 @@ def full_screen_toggle(self):
576573
self.window.showFullScreen()
577574

578575
def _widgetclosed(self):
576+
CloseEvent("close_event", self.canvas)._process()
579577
if self.window._destroying:
580578
return
581579
self.window._destroying = True

0 commit comments

Comments
 (0)