PDA

View Full Version : Cannot override copy shortcut



Paladin12
19th April 2010, 12:34
Dear all,

I have a custom context menu that acts on a table view.
There is a copy action in the menu.
It has a shortcut set via designer to be Ctrl+C.
When I use the Ctrl+C key combination the corresponding action is not triggered.
Instead the default copy-a-single-cell behaviour is executed.

What do I have to do to have a shortcut of an action invoke the action?

Are there any issues in overriding standard shortcuts such as copy (Ctrl+C)?

Kind Regards,

wysota
19th April 2010, 12:39
The action has to be "visible" for its shortcut to be active. You need to add it to some menu or button or make the action active in global context.

Paladin12
19th April 2010, 12:50
The actions are part of context menus generated at runtime. I guess this is not enough then?

wysota
19th April 2010, 13:01
No, that's not enough. You can press Ctrl+C when the context menu is visible and the action should work then but not when the menu is hidden.

You can try adding the action directly to the widget using QWidget::addAction(), maybe it will be sufficient.

Paladin12
19th April 2010, 14:28
That's very disappointing. So if I had a custom spreadsheet application I can only copy a range with Ctrl+C when the action is visible?

I wonder how the default copy shortcut works...

wysota
19th April 2010, 15:18
That's very disappointing. So if I had a custom spreadsheet application I can only copy a range with Ctrl+C when the action is visible?
How else would a user know there is an action with a Ctrl+C shortcut? :)


I wonder how the default copy shortcut works...
I don't know what you mean by "default copy shortcut" but you can install an application wide shortcut if you want. Not directly through QAction though.

Paladin12
19th April 2010, 15:27
I see now. I'm trying to implement many Ctrl+C's that behave differently depending upon the widget they are acting upon, and Qt does not support this. :crying:

I need something like a contextual shortcut, but they don't exist.

Thanks for your help anyway!

wysota
19th April 2010, 15:56
I see now. I'm trying to implement many Ctrl+C's that behave differently depending upon the widget they are acting upon, and Qt does not support this. :crying:
Why not?


I need something like a contextual shortcut, but they don't exist.
Every shortcut in Qt has a context. See the docs for QShortcut.