8000 Backport PR #26052: Improve Qt compatibility · matplotlib/matplotlib@ac9fe58 · GitHub
[go: up one dir, main page]

Skip to content

Commit ac9fe58

Browse files
oscargusmeeseeksmachine
authored andcommitted
Backport PR #26052: Improve Qt compatibility
1 parent bacd940 commit ac9fe58

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
@@ -48,6 +48,8 @@ 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
@@ -58,10 +60,14 @@ jobs:
5860
- os: ubuntu-20.04
5961
python-version: '3.10'
6062
extra-requirements: '-r requirements/testing/extra.txt'
63+
# https://github.com/matplotlib/matplotlib/pull/26052#issuecomment-1574595954
64+
pyqt6-ver: '!=6.5.1'
6165
# https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-2346
6266
pyside6-ver: '!=6.5.1'
6367
- os: ubuntu-20.04
6468
python-version: '3.11'
69+
# https://github.com/matplotlib/matplotlib/pull/26052#issuecomment-1574595954
70+
pyqt6-ver: '!=6.5.1'
6571
# https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-2346
6672
pyside6-ver: '!=6.5.1'
6773
- 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)
0