I would like to popup a menu, when user clicks on an object in QTreeWidgetItem. I though about catching signal contextMenuRequested from QWidget and then retrieving index from the view using itemAt. But this doesn't seem very pretty. Is there any easier way to be able to call a menu on an item inside a view?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- QML: Cannot read property 'xxx' of undefin
- How to get the background from multiple images by
- Evil ctypes hack in python
I'm using something like this:
and check which item triggered the signal by:
What I did with the new signal/slot style:
This will open a menu when you right-click within the your treeWidget. And if you click the 'print', in your console it will print out the item which has the current focus, it's the one that you right-clicked.
Note: the current item is not necessary the selected item, the selected item is the one you most recently clicked.
Write your own custom ItemDelegate and handle the click event in
QAbstractItemDelegate::editorEvent
. You can retreive the data in the cell from the QModelIndex. In C++ it would look like this: