Results 1 to 6 of 6

Thread: QTreeWidgetItem have contextMenu ?

  1. #1
    Join Date
    Dec 2008
    Location
    chinese
    Posts
    47
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default QTreeWidgetItem have contextMenu ?

    i need help.
    i want QTreeWidgetItem to show contextMenu on it be click, can somebody tell me how to make it?
    thanks

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidgetItem have contextMenu ?

    You will need to override treewidget context menu function.
    In this check if any item is under it and show menu based on the item.
    You can also ContextMenu ready in items, and from treewidget contextmenu function, get this menu and show it.

    or may be you can call some treewidget item function from treewidget contextmenu event.

    Hope something works for you

  3. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTreeWidgetItem have contextMenu ?

    at the first you need to set context menu policy for QTreeWidget
    Qt Code:
    1. ...
    2. m_tree->setContextMenuPolicy(Qt::CustomContextMenu);
    3. ...
    To copy to clipboard, switch view to plain text mode 
    then connect customContextMenuRequested with the slot which will create a context menu
    Qt Code:
    1. ...
    2. connect(m_tree, SIGNAL(customContextMenuRequested(const QPoint &)), SLOT(showContextMenu(const QPoint &)));
    3. ...
    To copy to clipboard, switch view to plain text mode 
    and last you need to create that slot
    Qt Code:
    1. void MyWidget::showContextMenu(const QPoint &pos)
    2. {
    3. QTreeWidgetItem *item = m_tree->itemAt(pos);
    4. if (!item)
    5. return;
    6.  
    7. QMenu menu(tr("Context menu"), this);
    8. //add needed actions
    9. menu.exec(m_tree->viewport()->mapToGlobal(pos));
    10. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  4. #4
    Join Date
    Dec 2008
    Location
    chinese
    Posts
    47
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidgetItem have contextMenu ?

    thanks everyone,i have work out the question follow your

  5. #5
    Join Date
    May 2012
    Location
    India
    Posts
    51
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: QTreeWidgetItem have contextMenu ?

    Thanks for such a nice reply . But here i am facing some problem like the action is being performed when we are clicking on any part of the UI .
    My requirement is whenever the user click on that menuitem , that time only the action shall be performed .

  6. #6
    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: QTreeWidgetItem have contextMenu ?

    So, you resurrected a 3.5 year old thread to tell us that something in a program you don't describe does something you don't expect when you click somewhere. Don't be surprised when no magic bullet answer is forthcoming.

Similar Threads

  1. hidden a QTreeWidgetItem
    By mattia in forum Newbie
    Replies: 6
    Last Post: 19th February 2014, 14:04
  2. Custom QTreeWidgetItem context menu?
    By AaronMK in forum Qt Programming
    Replies: 4
    Last Post: 1st February 2010, 04:42
  3. Contextmenu in Qtreeview
    By LordQt in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2009, 16:39
  4. Modify a ContextMenu
    By smarinr in forum Qt Programming
    Replies: 5
    Last Post: 10th May 2008, 17:41
  5. Replies: 3
    Last Post: 26th April 2008, 18:42

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.