PDA

View Full Version : Shortcuts for QActions...



ericV
19th October 2009, 12:08
Hello,
there probably are similar questions to the ones I am about to ask somewhere in the depths of the forum (which I have not found yet, at least nothing that will help me).

I have the following Problems with setting shortcuts for QActions:

1. I have a Widget that is built with 2 QLables and 1 QLineEdit. Its suposed to be a numeric indicator so most of the time it should be read only. But i want to be able to enter an editing mode when the user presses "F2" (or any other keysequence...)

So I did the following in my widget:


...
QAction *editAction= new QAction(this);
editAction->setShortcut(QKeySequence(Qt::Key_F2));
editAction->setShortcutContext(Qt::WidgetWithChildrenShortcut) ;

connect(editAction,SIGNAL(triggered())),this,SLOT( setEditable()));
...
void Display::setEditable()
{
valueDisp->setReadonly(false);
}


2. I have a MDI subwindow, with a custom texteditor widget in it. Here i have an action that removes the Frame (In order to lock the editor in position)
the action can be called from the mdi system menu, which cant be reached when there is no frame, so i want the Action to have a shortcut eg. "F6".
I have created the Action and given it such a shortcut, but it wont trigger.


I am pretty sure my problems have something to do with the focus when the shortcut is used, but i am not sure how i can correct this.

Can anyone guide me to the answer? ;)

Thank you for reading

Eric

scascio
19th October 2009, 14:03
So you need to trigger an action of a widget that is not focused?
( but how do you know which window needs to be reset on?)

Maybe you can manage your action one step higher in your widget hierarchy, to trigger it on or off,

Or maybe you can set your shorcut as Qt::ApplicationShortcut or Qt::WindowShortcut instead of Qt::WidgetWithChildrenShortcut

ericV
19th October 2009, 14:18
I am trying to handle the shortcuts from the parent, while the child has focus...

I did try using Qt::WidgetWithChildrenShortcut (seemed right to me from the documentation) to no effect...