[PyQt] ContextMenu for a TreeView

David Boddie dboddie at trolltech.com
Tue Feb 17 12:34:27 GMT 2009


On Tue Feb 17 01:31:01 GMT 2009, Doug Bell wrote:
> projetmbc at club-internet.fr wrote:
> > Hello,
> > is it possible to define a ContextMenu for a TreeView ?
>
> Yes, just override QWidget.contextMenuEvent for the view.

Without wanting to confuse things, I'd like to point out an alternative
approach: set the context menu policy and connect the widget's
customContextMenuRequested(const QPoint &) signal to a slot somewhere
in another object.

Something like this should do the trick:

  widget.setContextMenuPolicy(Qt.CustomContextMenu)
  self.connect(widget, SIGNAL("customContextMenuRequested (const QPoint &)"),
               self.mySlotToCreateTheMenu)

Resources:

http://www.riverbankcomputing.com/static/Docs/PyQt4/html/qwidget.html#setContextMenuPolicy
http://www.riverbankcomputing.com/static/Docs/PyQt4/html/qt.html#ContextMenuPolicy-enum
http://www.riverbankcomputing.com/static/Docs/PyQt4/html/qwidget.html#customContextMenuRequested

David


More information about the PyQt mailing list