I am trying to set up two-key shortcuts without modifiers in Pyside/PyQt4.
I have tried various combinations of QEvents and QKeySequences, but to no avail.
What I would like to do is something like this:
def keyPressEvent(self, event): if (event.key() == QtCore.Qt.Key_O) and (event.key() == QtCore.Qt.Key_P ): print('shortcut op accepted')
or
fileMenu.addAction(QtGui.QAction("Open Project", self, shortcut=QtGui.QKeySequence("P" and "O"),triggered=self.openProject))
where the users presses, O, then P and then the action occurs.
Does anyone know firstly if this is possible and if so how to do it?
For me "O, P" as arguments for the QKeySequence do the job.
Example:
from PySide import QtGui
def beep():
print('beep')
app = QtGui.QApplication([])
toolbar = QtGui.QToolBar()
toolbar.show()
action = QtGui.QAction("Action", toolbar, shortcut=QtGui.QKeySequence("O, P"), triggered=beep)
toolbar.addAction(action)
app.exec_()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With