[PyQt] context menus for QTreeWidgetItem?

Patrick Boucher pboucher at patrickboucher.com
Thu Apr 9 02:10:47 BST 2009


Hi Christian,

Implement the context menu on the QTreeWidget but when the context
menu signal (customContextMenuRequested(QPoint)) is triggered get the
item under the point with QTreeWidget.itemAt(QPoint) if the item is
None don't show any menu and return immediately otherwise show your
properly formatted menu according to whatever item is under the point.

Don't forget to remap your point's position when/before showing the
menu. The point coming into the slot is in widget coordinates while
you should show the menu according to global coordinates (look into
Widget.mapToGlobal(QPoint))

Cheers,
Patrick



On Wed, Apr 8, 2009 at 8:20 PM, Christian Aubert <chris at infixlabs.com> wrote:
> I currently have a context menu for the whole QTreeWidget but I need
> finer-grained control on a per item basis. Has anyone implemented context
> menus for QTreeWidgetItems? Any pointers?
>
> Christian
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>



More information about the PyQt mailing list