ActionX added to multiple widgets. How to determine which widget triggered the action
Hi,
I have an actionX defined in my MainWindow and I have added this action to the context menu of a few treewidgets.
In the MainWindow :: on_actionX_triggered() slot, how can I figure out which treewidget triggered the action?
I've tried the following with not much luck:
Code:
void MainWindow::on_actionX_triggered()
{
qDebug()<<sender(); //outputs: QAction(0xe957dd8)
qDebug()<<sender()->parent(); //outputs: MainWindow(0x28fdfc, name = "MainWindow")
}
Re: ActionX added to multiple widgets. How to determine which widget triggered the ac
The point of QAction is to represent a consistent action/state can be triggered/seen from multiple places. If you are trying to determine which user of a QAction triggered the action in order to do something different based on that information then you have several different actions.
Re: ActionX added to multiple widgets. How to determine which widget triggered the ac
No, in my case the actions are absolutely the same. What I'm actually trying to do is to execute the same action on a different user/caller.
Here is my exact situation:
I have an action added in a context menu of some treeviews, that changes the icon of a treeviewitem.
So basically, what my action does is:
Code:
treeItem
->setIcon
(0,
QIcon(":/Icons/NewIcon.ico"))
Now in order to get to that "treeItem", I need to get the parent tree first. In my particular case, only one tree is visible at a time so I'm checking which tree is currently visible and then I'm working my way down to the "treeItem" and apply the action. But I don't like this approach. It seams logical to be able to determine who called the action and not relying on a visibility...
Maybe I'm not thinking in the right direction... I'm open to new suggestions. :)