Every QWidget
has a contextMenuPolicy
property which defines what to do when context menu is requested. A simpliest way to do what you need is like this:
- Create
QAction
objects that call methods you want. - Add these actions to your tree widgets using
widget.addAction()
- Call
widget.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
That's it. Context menu for the widget will contain actions you added.