Merge pull request #1707 from pijyoi/pyqt61_compat

add PyQt6 6.1 forwards compatibility
This commit is contained in:
Ogi Moore 2021-04-10 20:27:04 -07:00 committed by GitHub
commit bb90ef1ec9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 6 deletions

View File

@ -376,6 +376,15 @@ if QT_LIB == PYQT6:
QtCore.QEvent.type = new_method
del new_method
# PyQt6 6.1 renames some enums and flags to be in line with the other bindings.
# "Alignment" and "Orientations" are PyQt6 6.0 and are used in the generated
# ui files. Pending a regeneration of the template files, which would mean a
# drop in support for PyQt6 6.0, provide the old names for PyQt6 6.1.
# This is strictly a temporary private shim. Do not depend on it in your code.
if hasattr(QtCore.Qt, 'AlignmentFlag') and not hasattr(QtCore.Qt, 'Alignment'):
QtCore.Qt.Alignment = QtCore.Qt.AlignmentFlag
if hasattr(QtCore.Qt, 'Orientation') and not hasattr(QtCore.Qt, 'Orientations'):
QtCore.Qt.Orientations = QtCore.Qt.Orientation
# USE_XXX variables are deprecated
USE_PYSIDE = QT_LIB == PYSIDE

View File

@ -826,9 +826,16 @@ class ROI(GraphicsObject):
"""
return True
def movePoint(self, handle, pos, modifiers=QtCore.Qt.KeyboardModifiers(0), finish=True, coords='parent'):
def movePoint(self, handle, pos, modifiers=None, finish=True, coords='parent'):
## called by Handles when they are moved.
## pos is the new position of the handle in scene coords, as requested by the handle.
if modifiers is None:
try:
# this works for PyQt6 6.1 and other bindings
modifiers = QtCore.Qt.KeyboardModifier.NoModifier
except AttributeError:
# this works for PyQt6 6.0 and other bindings
modifiers = QtCore.Qt.KeyboardModifiers(0)
newState = self.stateCopy()
index = self.indexOfHandle(handle)
@ -1454,7 +1461,14 @@ class Handle(UIGraphicsItem):
self.currentPen = self.hoverPen
self.movePoint(pos, ev.modifiers(), finish=False)
def movePoint(self, pos, modifiers=QtCore.Qt.KeyboardModifiers(0), finish=True):
def movePoint(self, pos, modifiers=None, finish=True):
if modifiers is None:
try:
# this works for PyQt6 6.1 and other bindings
modifiers = QtCore.Qt.KeyboardModifier.NoModifier
except AttributeError:
# this works for PyQt6 6.0 and other bindings
modifiers = QtCore.Qt.KeyboardModifiers(0)
for r in self.rois:
if not r.checkPointMove(self, pos, modifiers):
return

View File

@ -259,9 +259,10 @@ class Renderer(GraphicsView):
def deserialize_wheel_event(self, wheel_event):
pos, gpos, pixelDelta, angleDelta, btns, mods, phase, inverted = wheel_event
btns = QtCore.Qt.MouseButtons(btns)
mods = QtCore.Qt.KeyboardModifiers(mods)
phase = QtCore.Qt.ScrollPhase(phase)
if QT_LIB != 'PyQt6':
btns = QtCore.Qt.MouseButtons(btns)
mods = QtCore.Qt.KeyboardModifiers(mods)
phase = QtCore.Qt.ScrollPhase(phase)
return QtGui.QWheelEvent(pos, gpos, pixelDelta, angleDelta, btns, mods, phase, inverted)
def mousePressEvent(self, mouse_event):