QKeySequence behavior differences/crashes in PySide2 compared to PySide?
Unsolved
Qt for Python
-
As I'm currently porting a gui application from Python 2.7.14/PySide 1.2.4 to Python 3.7.1/PySide2 5.11.2 I'm encountering a few problems with the shortcut machinery. More specifically:
QKeySequence
instantiation seems to return different/surprising results in PySide2 compared to PySide.- The
+
operators onQt.Key_*
enums don't seem to return the expected results. For exampleQKeySequence(Qt.SHIFT + Qt.CTRL + Qt.Key_Z)
doesn't seem to work properly. - When using string codes for instantiation of
QKeySequences
it works, for exampleQKeySequence("Shift+Ctrl+Z")
seems functional. - Instantiation with
QKeySequence.StandardKey
likeQKeySequence(QKeySequence.Redo)
simply crashes in PySide2. - PyQt5 doesn't seem to have any of these issues (as tested by users on StackOverflow). Could this be issues/bugs with the binding of PySide2 _(possibly related to enum addition)?
Are these known bugs? Did something change in the expected usage? Did I miss something in the docs? Are there differences in how enums are added?
Win7x64/Python 3.7.1/PySide2 5.11.2 (disfunctional/crashing)
# -*- coding: utf-8 -*- """Test QKeySequence equality/matching in PySide2.""" from PySide2.QtCore import Qt from PySide2.QtGui import QKeySequence sequence_a = QKeySequence("Shift+Ctrl+Z") sequence_b = QKeySequence(Qt.SHIFT + Qt.CTRL + Qt.Key_Z) # string representation print(sequence_a.toString()) print(sequence_b.toString()) print("-"*20) # equality/matching print(sequence_a.matches(sequence_b)) print(sequence_a == sequence_b) print("-"*20) # this causes a crash in PySide2 (Process finished with exit code -1073741819 (0xC0000005)) print(QKeySequence(QKeySequence.Redo)) # Ctrl+Shift+Z # [ # -------------------- # PySide2.QtGui.QKeySequence.SequenceMatch.NoMatch # False # -------------------- # Process finished with exit code -1073741819 (0xC0000005)
Win7x64/Python 2.7.14/PySide 1.2.4 (working)
# -*- coding: utf-8 -*- """Test QKeySequence equality/matching in PySide.""" from PySide.QtCore import Qt from PySide.QtGui import QKeySequence sequence_a = QKeySequence("Shift+Ctrl+Z") sequence_b = QKeySequence(Qt.SHIFT + Qt.CTRL + Qt.Key_Z) # string representation print(sequence_a.toString()) print(sequence_b.toString()) print("-"*20) # equality/matching print(sequence_a.matches(sequence_b)) print(sequence_a == sequence_b) print("-"*20) # this works in PySide print(QKeySequence(QKeySequence.Redo)) # Ctrl+Shift+Z # Ctrl+Shift+Z # -------------------- # PySide.QtGui.QKeySequence.SequenceMatch.ExactMatch # True # -------------------- # PySide.QtGui.QKeySequence(67108953, 0, 0, 0)
It seems that the following code works equally on Python2 and 3:
print(Qt.SHIFT + (Qt.CTRL + Qt.Key_Z)) print(QKeySequence(Qt.SHIFT + (Qt.CTRL + Qt.Key_Z)).toString()) # 100663386 # Ctrl+Shift+Z