QKeySequence differences between PySide and PySide2

0

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 on Qt.Key_* enums don't seem to return the expected results. For example QKeySequence(Qt.SHIFT + Qt.CTRL + Qt.Key_Z) doesn't seem to work properly.
  • When using string codes for instantiation of QKeySequences it works, for example QKeySequence("Shift+Ctrl+Z") seems functional.
  • Instantiation with QKeySequence.StandardKey like QKeySequence(QKeySequence.Redo) simply crashes in PySide2.

Are these known bugs? Did something change in the expected usage? Did I miss something in the docs?

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)
python
qt
pyside
pyside2
asked on Stack Overflow Dec 8, 2018 by timmwagener • edited Dec 8, 2018 by timmwagener

1 Answer

0

As for now, two possible workarounds have emerged:


  • Error: QKeySequence(Qt.SHIFT + Qt.CTRL + Qt.Key_Z).toString() --> "["
  • Fix with enforced precedence: QKeySequence(Qt.SHIFT + (Qt.CTRL + Qt.Key_Z)).toString() --> "Ctrl+Shift+Z"
  • Fix with bitwise or operator: QKeySequence(Qt.ShiftModifier | Qt.CTRL | Qt.Key_Z).toString() --> "Ctrl+Shift+Z"

While they seem to solve the direct problem at hand, I don't find them to be all that great for various reasons. The general issue may still possibly qualify as PySide2 bug!?

answered on Stack Overflow Dec 8, 2018 by timmwagener

User contributions licensed under CC BY-SA 3.0