문제

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..

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top