Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add backend for Qt6 (support for PyQt6, PySide6)#19674

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
mfitzp wants to merge2 commits intomatplotlib:masterfrommfitzp:qt6-backend

Conversation

mfitzp
Copy link
Member

PR Summary

This PR adds support for Qt6, with support for both PyQt6 and PySide6 libraries.

For the most part PySide6 is source-compatible with PySide2, aside from the imports and some small changes (see below). PyQt6 is quite different. The main changes that affect us here are

  • Enums are no longer available at the top level of modules/objects. For example, previouslyQt.GlobalColor.white was previously available asQt.white. This short style was present in PyQt5 & PySide2 and is still supported in PySide6. PySide6 also supports the longer version (but...)
  • While enum types are identical between PyQt6 & PySide6, flag types have different names. SoQt.GlobalColor.white (enum) is the same in both. But alignment flags are inQt.Alignment.AlignLeft in PyQt6 andQt.AlignmentFlag.AlignLeft in PySide6.
  • (this may be a bug) Mouse events in PyQt6 no longer have the.pos() attribute. We can use.position() instead.
  • PyQt6 no longer supports usingexec_(), must useexec(). PySide6 is exactly the reverse.
  • Qt.MidButton is nowQt.MiddleButton

The code to work around these differences is inqt_compat.py. Because of the differences in flag naming, I've opted to just copy the entries from the enums/flags to the parent object (matching PyQt5/PySide2). There is a further shim for QDialog to account for PyQt no longer havingexec_().

Since this adds new files, the diff doesn't show the changes. Below is a diff between v5 and v6.

backends (qt6-backend) $ diff backend_qt5.py backend_qt6.py158c158<                     "PyQt4", "sip", "PySide", "PySide2", "Shiboken"])--->                     "PyQt4", "sip", "PySide", "PySide2", "PySide6", "Shiboken"])205c205<                QtCore.Qt.MidButton: MouseButton.MIDDLE,--->                QtCore.Qt.MiddleButton: MouseButton.MIDDLE,279c279<             x, y = self.mouseEventCoords(event.pos())--->             x, y = self.mouseEventCoords(event.position())306c306<         x, y = self.mouseEventCoords(event.pos())--->         x, y = self.mouseEventCoords(event.position())313c313<         x, y = self.mouseEventCoords(event.pos())--->         x, y = self.mouseEventCoords(event.position())321c321<         x, y = self.mouseEventCoords(event)--->         x, y = self.mouseEventCoords(event.position())325c325<         x, y = self.mouseEventCoords(event)--->         x, y = self.mouseEventCoords(event.position())331,351c331,340<     if QtCore.qVersion() >= "5.":<         def wheelEvent(self, event):<             x, y = self.mouseEventCoords(event)<             # from QWheelEvent::delta doc<             if event.pixelDelta().x() == 0 and event.pixelDelta().y() == 0:<                 steps = event.angleDelta().y() / 120<             else:<                 steps = event.pixelDelta().y()<             if steps:<                 FigureCanvasBase.scroll_event(<                     self, x, y, steps, guiEvent=event)<     else:<         def wheelEvent(self, event):<             x = event.x()<             # flipy so y=0 is bottom of canvas<             y = self.figure.bbox.height - event.y()<             # from QWheelEvent::delta doc<             steps = event.delta() / 120<             if event.orientation() == QtCore.Qt.Vertical:<                 FigureCanvasBase.scroll_event(<                     self, x, y, steps, guiEvent=event)--->     def wheelEvent(self, event):>         x, y = self.mouseEventCoords(event.position())>         # from QWheelEvent::delta doc>         if event.pixelDelta().x() == 0 and event.pixelDelta().y() == 0:>             steps = event.angleDelta().y() / 120>         else:>             steps = event.pixelDelta().y()>         if steps:>             FigureCanvasBase.scroll_event(>                 self, x, y, steps, guiEvent=event)488c477,480<                 pen = QtGui.QPen(QtCore.Qt.black, 1 / self._dpi_ratio)--->                 pen = QtGui.QPen(>                     QtCore.Qt.black,>                     1 / self._dpi_ratio>                 )1015c1007< class _BackendQT5(_Backend):---> class _BackendQT6(_Backend):

The differences being so minor, it may make sense to implement Qt6 based on Qt5 (or both vs a base).

PR Checklist

  • Has pytest style unit tests (andpytest passes).
  • IsFlake 8 compliant (runflake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).
  • Conforms to Matplotlib style conventions (installflake8-docstrings and runflake8 --docstring-convention=all).
  • New features have an entry indoc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented indoc/api/next_api_changes/ (follow instructions in README.rst there).

@jklymak
Copy link
Member

Thanks for this, however, there is already#19255

@mfitzp
Copy link
MemberAuthor

Thanks for this, however, there is already#19255

Oops. I'd searched + missed it. Will close

@mfitzpmfitzp closed thisMar 9, 2021
@anntzer
Copy link
Contributor

@mfitzp if you could by any chance help with investigating the CI crash on#19255 that would be super helpful :)

mfitzp reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@mfitzp@jklymak@anntzer

[8]ページ先頭

©2009-2025 Movatter.jp