[SOLVED] QKeySequence only for one widget
-
Hello everyone!
I have MainWindow with WebView in it, StatusBar and Subclassed QFrame widget on StatusBar.
in my QFrame widget I create action for key sequence as follow:
@
ExSearchBar::ExSearchBar(QWidget *parent):QFrame(parent)
{.....
QKeySequence keys_esc(Qt::Key_Escape);
this->esc = new QAction(this);
connect(this->esc, SIGNAL(triggered()), this, SLOT(search_hide()));
this->esc->setShortcut(keys_esc);
this->addAction(this->esc);
}
@The problem is, what the action triggers even if currently active(focused) widget is WebView(or WebFrame)...
How can I restrict this QKeySequence action only for widget it is created for?(Should be triggered only when widget or its childs are in focus)Thanks in advance!
-
Try changing the "shortcut context":http://qt-project.org/doc/qt-4.8/qaction.html#shortcutContext-prop .
-
you should set the shortcutContext to 'Qt::WidgetShortcut', which will enable the action only if the widget itself has focus, but not any of its children.
-
@
ExSearchBar::ExSearchBar(QWidget *parent):QFrame(parent)
{
.....QKeySequence keys_esc(Qt::Key_Escape);
this->esc = new QAction(this);
connect(this->esc, SIGNAL(triggered()), this, SLOT(search_hide()));
this->esc->setShortcut(keys_esc);
this->esc->setShortcutContext(Qt::WindowShortcut);
this->addAction(this->esc);
}@Doesn't work... it is still triggered.. . and this->hasFocus() is false...
-
you set the shortcutContxt to 'WindowShortcut' which is the default, meaning the behaviour shouldn't have changed.
Try changing it to 'Qt::WidgetShortcut'.
-
My bad :) Thank you guys! Works!