Results 1 to 3 of 3

Thread: ActionX added to multiple widgets. How to determine which widget triggered the action

  1. #1
    Join Date
    Jan 2013
    Posts
    13
    Thanks
    4

    Default 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:
    Qt Code:
    1. void MainWindow::on_actionX_triggered()
    2. {
    3. qDebug()<<sender(); //outputs: QAction(0xe957dd8)
    4. qDebug()<<sender()->parent(); //outputs: MainWindow(0x28fdfc, name = "MainWindow")
    5. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default 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.

  3. #3
    Join Date
    Jan 2013
    Posts
    13
    Thanks
    4

    Default 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:
    Qt Code:
    1. treeItem->setIcon(0,QIcon(":/Icons/NewIcon.ico"))
    To copy to clipboard, switch view to plain text mode 
    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.

Similar Threads

  1. Replies: 2
    Last Post: 28th September 2012, 17:15
  2. action triggered no emit
    By waiter in forum Newbie
    Replies: 3
    Last Post: 27th September 2012, 23:26
  3. find out which shortcut triggered action
    By qt_gotcha in forum Newbie
    Replies: 3
    Last Post: 23rd August 2010, 20:27
  4. Custom action added to make by qmake
    By NTwoO in forum Qt Programming
    Replies: 2
    Last Post: 2nd March 2007, 10:17
  5. Replies: 3
    Last Post: 1st October 2006, 15:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.