PDA

View Full Version : copy/paste actions in main window menu



magland
2nd October 2007, 11:48
I have a cut/copy/paste menu in my QMainWindow, and I've set the standard shortcuts. I have a number of child windows of different types.

When, for example, Ctrl+C is pressed in one of the child windows, I would like the keyPressEvent to be called first in that child window. But that's not what happens... instead the main window takes over.

My workaround so far has been for the main window to figure out who has the focus and then pass the event back down - but I don't want to do that any more.

What's the right way to handle this? Any suggestions?

wysota
2nd October 2007, 11:55
Try reimplementing event() for the child (or apply an event filter) and process the key yourself there. You can also change the context of the shortcut to Qt::WidgetShortcut, maybe this will be enough.

magland
2nd October 2007, 12:15
Try reimplementing event() for the child (or apply an event filter) and process the key yourself there. You can also change the context of the shortcut to Qt::WidgetShortcut, maybe this will be enough.

That's a good hint, Wysota. I'm now using setShortcutContext(Qt::WidgetShortcut), and in effect it completely disables the shortcuts -- but that's a good thing. The advantage of this, as opposed to removing the shortcuts completely, is that the "Ctrl+C" text still appears in the menu.

My last step is to catch the QKeyEvent in the main window and send them down to the children when appropriate. Could you please tell me: does a keyPressEvent bubble up/bubble down?

Thanks

wysota
2nd October 2007, 12:33
All events propagate from children to parents until they are handled.