Skip to content
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

Add support for Qt 6 and Python 3.10 #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
27 changes: 19 additions & 8 deletions matplotlib_backend_qtquick/backend_qtquick.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
FigureCanvasBase, NavigationToolbar2,
MouseButton)
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt5 import (
TimerQT, SPECIAL_KEYS, MODIFIER_KEYS, cursord)
from matplotlib.backends.backend_qt import (
TimerQT, SPECIAL_KEYS, _MODIFIER_KEYS as MODIFIER_KEYS, cursord)
from .qt_compat import (
QtCore, QtGui, QtQuick, QtWidgets,
QT_API, QT_API_PYSIDE2)
QT_API, QT_API_PYSIDE2, QT_API_PYSIDE6)


class FigureCanvasQtQuick(QtQuick.QQuickPaintedItem, FigureCanvasBase):
Expand All @@ -25,7 +25,7 @@ class FigureCanvasQtQuick(QtQuick.QQuickPaintedItem, FigureCanvasBase):

# map Qt button codes to MouseEvent's ones:
buttond = {QtCore.Qt.LeftButton: MouseButton.LEFT,
QtCore.Qt.MidButton: MouseButton.MIDDLE,
QtCore.Qt.MiddleButton: MouseButton.MIDDLE,
QtCore.Qt.RightButton: MouseButton.RIGHT,
QtCore.Qt.XButton1: MouseButton.BACK,
QtCore.Qt.XButton2: MouseButton.FORWARD,
Expand Down Expand Up @@ -109,7 +109,7 @@ def _draw_rect_callback(painter):
pen = QtGui.QPen(QtCore.Qt.black, 1 / self.dpi_ratio,
QtCore.Qt.DotLine)
painter.setPen(pen)
painter.drawRect(*(pt / self.dpi_ratio for pt in rect))
painter.drawRect(QtCore.QRectF(*(pt / self.dpi_ratio for pt in rect)))
else:
def _draw_rect_callback(painter):
return
Expand Down Expand Up @@ -154,7 +154,7 @@ def _draw_idle(self):
# Uncaught exceptions are fatal for PyQt5, so catch them.
traceback.print_exc()

def geometryChanged(self, new_geometry, old_geometry):
def geometryChangeHelper(self, new_geometry, old_geometry):
w = new_geometry.width() * self.dpi_ratio
h = new_geometry.height() * self.dpi_ratio

Expand All @@ -167,6 +167,17 @@ def geometryChanged(self, new_geometry, old_geometry):
self.figure.set_size_inches(winch, hinch, forward=False)
FigureCanvasBase.resize_event(self)
self.draw_idle()

# Overload for Qt 6
def geometryChange(self, new_geometry, old_geometry):
self.geometryChangeHelper(new_geometry, old_geometry)
QtQuick.QQuickPaintedItem.geometryChange(self,
new_geometry,
old_geometry)

# Overload for Qt 5
def geometryChanged(self, new_geometry, old_geometry):
self.geometryChangeHelper(new_geometry, old_geometry)
QtQuick.QQuickPaintedItem.geometryChanged(self,
new_geometry,
old_geometry)
Expand Down Expand Up @@ -239,7 +250,7 @@ def mouseDoubleClickEvent(self, event):
guiEvent=event)

def wheelEvent(self, event):
x, y = self.mouseEventCoords(event.pos())
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
Expand Down Expand Up @@ -349,7 +360,7 @@ class NavigationToolbar2QtQuick(QtCore.QObject, NavigationToolbar2):
def __init__(self, canvas, parent=None):

# I think this is needed due to a bug in PySide2
if QT_API == QT_API_PYSIDE2:
if QT_API in [QT_API_PYSIDE2, QT_API_PYSIDE6]:
QtCore.QObject.__init__(self, parent)
NavigationToolbar2.__init__(self, canvas)
else:
Expand Down
4 changes: 2 additions & 2 deletions matplotlib_backend_qtquick/backend_qtquickagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def paint(self, p):
stringBuffer = self.renderer.tostring_argb()

# convert the Agg rendered image -> qImage
qImage = QtGui.QImage(stringBuffer, self.renderer.width,
self.renderer.height,
qImage = QtGui.QImage(stringBuffer, int(self.renderer.width),
int(self.renderer.height),
QtGui.QImage.Format_RGBA8888)
if hasattr(qImage, 'setDevicePixelRatio'):
# Not available on Qt4 or some older Qt5.
Expand Down
Loading