PDA

View Full Version : How can I show a context menu when right clicking on QTreeWidgetItem?



Joachie
12th April 2009, 18:05
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.

drhex
12th April 2009, 21:32
override contextEvent() and feed the pos() of the event to the QTreeWidget's itemAt() to find out which tree item you right-clicked.

Joachie
13th April 2009, 00:53
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.

Joachie
13th April 2009, 20:34
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.

spirit
13th April 2009, 20:37
read this (http://www.qtcentre.org/forum/p-qtreewidgetitem-have-contextmenu--post93472/postcount3.html).