Results 1 to 3 of 3

Thread: How to pass a TreeWidgetItem in QAction trigger signal/slot

  1. #1
    Join Date
    Jun 2018
    Location
    India
    Posts
    33
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Question How to pass a TreeWidgetItem in QAction trigger signal/slot

    Hi,

    I created a right click menu option for a QTreeWidgetItem using CustomContextMenu. Under this, created a QAction ,uopn which I need to pass the currentTreeItem in signal triggered(). How can i achieve that?

    Found that we can call QAction->setData().. But not sure, how to convert QTreeWidgetItem to a QVariant ?

    Any suggestion please

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,987
    Thanks
    232
    Thanked 628 Times in 618 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to pass a TreeWidgetItem in QAction trigger signal/slot

    How are you using your QTreeWidget? Is it part of a larger composite QWidget of some sort? The easiest thing to do is to handle the triggered() signal in a slot for that composite widget, and once in the slot use the QTreeWidget pointer to retrieve the current item. (QTreeWidget::currentItem())

    If you are handling the triggered() signal in a different class from the one that contains the QTreeWidget, then you can add a slot to that class and connect it to the QTreeWidget::currentItemChanged() signal and save the pointer to the current item in a member variable. You use that later when handling the QAction::triggered() signal.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jun 2018
    Location
    India
    Posts
    33
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to pass a TreeWidgetItem in QAction trigger signal/slot

    Thanks very much
    As my QAction and QTreeWidget are in same class, I followed the first approach where I am using (QTreeWidget::currentItem()) in the triggered() slot to retrieve the current item.

Similar Threads

  1. Replies: 3
    Last Post: 25th October 2013, 10:39
  2. QAction, triggered signal dont call a slot
    By kaszewczyk in forum Newbie
    Replies: 6
    Last Post: 5th October 2010, 21:30
  3. Trigger QAction by 'Key_Escape'
    By Raccoon29 in forum Newbie
    Replies: 5
    Last Post: 3rd April 2008, 10:24
  4. Replies: 3
    Last Post: 19th November 2007, 15:31
  5. Replies: 2
    Last Post: 16th August 2007, 00:20

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.