Focus on QAction
-
suppose i have QAction and this action is being used by toolbuttons and menu items. is there anyway for me to detect when the underlying widget gets/loses focus?
-
What 'underlying' widget? A QAction is not a visual element.
-
some more details will help here. What is the relation of QAction to other widget ? What is the underlying widget etc.
Also it is good check the focusInEvent handler.
-
the QAction could be tied to multiple widget and i wanted to see if any of the underlying widgets had focus. therefore, i am thinking of doing the following by tying the hovered signal from QAction to a slot with the following coding:
QList <QWidget *> widget_list = sender()->associatedWidgets();
for(i = 0; i != widget_list.size(); ++i) {
if (widget_list.at(i)->hasFocus())
then do something
else
do something else
}i think this will work?
-
on second thought the hovered signal is not good enough because then i could never detect then an underlying widget has lost focus. so i am still not sure for the next step.
-
what i really need is an enter/leave event on a QAction which i don't think is available.
-
Hi,
Indeed, it's not. A QAction doesn't have a "physical" representation. What you could do is create an action manager that would react when your widgets get/lose their focus.
Hope it helps
-
you are not talking about a QActionGroup here right? what is an action manager an example would be helpful.
-
Indeed
An action manager is a central object where you handle e.g. the redirection of the signals and slots based on your current widget or the shortcuts
IIRC, Qt Creator has such a concept, you can have a look at the sources