Skip to content

Improve Qt compatibility #26052

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
merged 3 commits into from
Jun 3, 2023
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
6 changes: 6 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 10 additions & 12 deletions lib/matplotlib/backends/backend_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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
Expand Down