Contextmenu in a QTreeWidget with PyQT

blaven at blaven at
Wed Nov 28 00:26:02 CET 2007

On Nov 22, 8:30 am, David Boddie <da... at> wrote:
> On Wed Nov 21 19:46:48 CET 2007,blavenwrote:
> > I apologize in advance if this is not the correct forum to ask this
> > and if someone knows a better place, please let me know.
> There is a mailing list for PyQt/PyKDE issues:
> It's not a problem to post questions here - some of the people on that list
> also read python-list/comp.lang.python.
> > But, I am trying to create a Contextmenu (a right-click popup menu) from
> > within a QTreeWidget.  I tried setting the contextMenuPolicy to
> > CustomContextMenu and then handling the signal
> > customContextMenuRequested() but nothing seems to be happening.  ie:
> >    self.tree = QTreeWidget()
> >    self.tree.setContextMenuPolicy(Qt.CustomContextMenu)
> > self.connect(self.tree,SIGNAL('customContextMenuRequested()'),
> >              self.newContext)
> You need to specify the parameters that the signal passes in the signature:
>   self.connect(self.tree,SIGNAL('customContextMenuRequested(QPoint)'),
>                self.newContext)
> In this case, a QPoint object is passed; see the documentation for more
> details:
> > Does anyone have a sample or tutorial on how to do this?  One other
> > question, whe I right click, it changes the selection in the
> > TreeWidget, would I need to remove the handler for right clicks to get
> > the menu?
> With your custom context menu enabled, you may find that right clicks no
> longer cause the selection to change. If it does, post another question,
> either here or on the PyQt/PyKDE list, and I'm sure someone will help you
> out.
> Good luck!
> David

Hello again.  It looks like I got the contextMenu to pop up but it was
as I feared.
When I right click to bring up the menu, it also changes the selection
in the background.
Is there a way to disable the right clicking for the QTreeWidget yet
still retain the
contextMenu? Thanks!


More information about the Python-list mailing list