Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two key shortcuts

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?

like image 321
Simon Skinner Avatar asked Dec 02 '25 02:12

Simon Skinner


1 Answers

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_()
like image 54
Trilarion Avatar answered Dec 03 '25 19:12

Trilarion