0

I have a QMainWindow with a menu bar, including menu items for Save, Open and Quit with the usual shortcuts. It creates a QTableWidget that lists a bunch of different categories from which the user can choose (at his option).

If the user clicks into the QTableWidget to change categories, the widget takes the focus. That's mostly what I want, but unfortunately it also seems to steal the menu shortcuts, so that pressing Ctrl+S no longer triggers the save.

I experimented with keyPressEvent to solve this, but it seems like overkill even if I do get it working. Isn't there a way to delegate all the control/menu keys back to the QMainWindow ?

Brian B
  • 1,410
  • 1
  • 16
  • 30

1 Answers1

1

There must be an issue with how you are creating your QMenuBar. Here is an example that works just fine for me. The Save continues to function regardless of focus being in the table:

class Window(QtGui.QMainWindow):

    def __init__(self):
        super(Window, self).__init__()
        self.resize(640,480)

        menuBar = self.menuBar()
        menu = menuBar.addMenu("&File")
        action = menu.addAction("&Save", self.doAction)
        action.setShortcuts(QtGui.QKeySequence.Save)

        self.view = QtGui.QTableWidget(5,5)
        self.setCentralWidget(self.view)

    def doAction(self):
        print "Save"
jdi
  • 90,542
  • 19
  • 167
  • 203