I am trying to develop an application with a very modular approach to commands and thought it would be nice if I used pyqt to use QAction to associate shortcuts with commands.
However, it seems that action shortcuts only work when an action is displayed in a menu or toolbar. Does anyone know a way to make this action work without its visibility?
Below is an example of code that shows what I'm trying. Thanks,
Andre
from PyQt4 import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
class TesteMW(QMainWindow):
def __init__(self, *args):
QMainWindow.__init__(self, *args)
self.create_action()
def create_action(self):
self.na = QAction(self)
self.na.setText('Teste')
self.na.setShortcut('Ctrl+W')
self.connect(self.na, SIGNAL('triggered()'), self.action_callback)
def action_callback(self):
print 'action called!'
app = QApplication(sys.argv)
mw = TesteMW()
mw.show()
app.exec_()
user164871
source
share