Frage

i have 2 treewidgets placed in a frame in mainwindow. how can i have 2 different set of context menu options for the 2 treewidgets? i need individual set of right click options for the treewidgets.Thanks in advance..

War es hilfreich?

Lösung

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:

  1. Create QAction objects that call methods you want.
  2. Add these actions to your tree widgets using widget.addAction()
  3. Call widget.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)

That's it. Context menu for the widget will contain actions you added.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top