I use QShortcut inside a widget to close the widget by pressing esc.
shortcut_esc = new QShortcut(this);
shortcut_esc->setKey(Qt::Key_Escape);
connect(shortcut_esc,SIGNAL(activated ()),this,SLOT( myslot() ));
there are 2 differnet ways for a user to open the widget. in the first way everything works fine, the secound the shortcut doesn't work.
in the paint -event of the widget i put a debug-message to detect which widget as the focus:
qDebug() << "focus widget: " << QApplication::focusWidget() << focusWidget() << shortcut_esc->isEnabled() << local->hasFocus() << isActiveWindow() << hasFocus();
the output is the same for both ways, so i think the focus is positioned right.
when the user clicks anywhere in widget, the shortcut works fine even for the secound way.
am i missing something?
where is the difference between clicking on a widget and use the setFocus() Member?
Bookmarks