Results 1 to 5 of 5

Thread: How can I show a context menu when right clicking on QTreeWidgetItem?

  1. #1
    Join Date
    Apr 2009
    Posts
    20
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default How can I show a context menu when right clicking on QTreeWidgetItem?

    I have a QTreeWidget, which is populated with QTreeWidgetItems. How do I setup a handler so that when a user right clicks on each tree item, different context menus can be shown?

    Many thanks, I tried a few things like the contextMenuPolicy but that only appears to work on the QTreeWidget itself, not its actual items.

  2. #2
    Join Date
    Jan 2006
    Location
    Knivsta, Sweden
    Posts
    153
    Thanks
    30
    Thanked 13 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: How can I show a context menu when right clicking on QTreeWidgetItem?

    override contextEvent() and feed the pos() of the event to the QTreeWidget's itemAt() to find out which tree item you right-clicked.

  3. #3
    Join Date
    Apr 2009
    Posts
    20
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How can I show a context menu when right clicking on QTreeWidgetItem?

    Quote Originally Posted by drhex View Post
    override contextEvent() and feed the pos() of the event to the QTreeWidget's itemAt() to find out which tree item you right-clicked.
    This doesn't work because the event doesn't get fired when right clicking on a tree item, only when right clicking on the header of the tree widget.
    Last edited by Joachie; 13th April 2009 at 01:13.

  4. #4
    Join Date
    Apr 2009
    Posts
    20
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How can I show a context menu when right clicking on QTreeWidgetItem?

    Any other suggestions on this? There must be an easy way to do this no? I can't imagine nobody is showing right click context sensitive menus in QT apps.

  5. #5
    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: How can I show a context menu when right clicking on QTreeWidgetItem?

    read this.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. Custom QTreeWidgetItem context menu?
    By AaronMK in forum Qt Programming
    Replies: 4
    Last Post: 1st February 2010, 04:42
  2. Context Menu on QTableWidget
    By ankurjain in forum Qt Programming
    Replies: 9
    Last Post: 17th December 2009, 09:52
  3. Custom context menu in QTreeView
    By ttvo in forum Qt Programming
    Replies: 5
    Last Post: 3rd April 2009, 22:29
  4. Shortcut key for context menu
    By darshan.hardas in forum Qt Programming
    Replies: 1
    Last Post: 28th December 2008, 20:32
  5. Replies: 4
    Last Post: 25th June 2007, 20:40

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.