Reputation: 53
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?
Upvotes: 3
Views: 1172
Reputation: 10859
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_()
Upvotes: 3