[Qt-interest] HowTo: set application-wide shortcuts without associated Widget?
kent williams
nkwmailinglists at gmail.com
Fri Feb 25 19:23:51 CET 2011
I'll answer my own question -- finally got the right combo of search
terms to find the answer:
http://stackoverflow.com/questions/1346964/use-qaction-without-adding-to-menu-or-toolbar
If anyone else runs into this, the actions I create can be added to my
app's mainWindow, and the shortcut context is set to
Qt::ApplicationShortcut:
void
QImageEval2Window::
AddKeyCommand(const char *name,QKeySequence &sequence)
{
QAction *action(new QAction(this));
action->setObjectName(name);
action->setShortcut(sequence);
action->setShortcutContext(Qt::ApplicationShortcut);
connect(action,SIGNAL(triggered()),
this,SLOT(changeSlice()));
this->addAction(action);
}
On Fri, Feb 25, 2011 at 12:15 PM, kent williams
<nkwmailinglists at gmail.com> wrote:
> I would like to have some keyboard shortcuts in my application that
> aren't associated with a menu item or pushbutton or other widget.
> Specifically I have 3 sliders and want to change their values based on
> keystrokes. For example Ctrl+K moves one of the sliders left, Ctrl+L
> moves it right, with other pairs of keys controlling the other two
> sliders.
>
> What I tried was this:
>
> void
> QImageEval2Window::
> AddKeyCommand(const char *name,QKeySequence &sequence)
> {
> QAction *action(new QAction(this));
> action->setObjectName(name);
> action->setShortcut(sequence);
> // changeSlice() uses the objectName to decide which
> // slider to move which direction.
> connect(action,SIGNAL(triggered()),
> this,SLOT(changeSlice()));
> }
>
> So I create actions, they have accellerators, but they aren't part of
> a menu or toolbar.
>
> I could make this work by adding the actions a menu, or actions to a
> toolbar, but it seems like there should be some way to set some global
> keyboard shortcuts, the way Control+Q is the application-wide 'quit'
> shortcut.
>
More information about the Qt-interest-old
mailing list