[Qt-interest] How do I have a context menu associated with QTreeWidgetItem
william.crocker at analog.com
william.crocker at analog.com
Thu Feb 18 00:26:26 CET 2010
kent williams wrote:
> I think the basic answer is "U R DOING IT RONG" but here goes...
>
> I want a context menu to pop up when I right click on an item in a QTreeWidget.
>
> According to "C++ GUI Programming with QT 4":
>
> "A more sophisticated way of providing context menus is to reimplement
> the QWidget::contextMenuEvent() function, create a QMenu widget,
> populate it with desired actions, and call exec() on it."
>
> The problem I'm having is that QTreeWidgetItem doesn't derive from
> QWidget, so i can derive a subclass from QTreeWidgetItem, so I can't
> re-implement the contextMenuEvent.
>
> QTreeWidgetItem also doesn't derive from QObject, so I can't use
> connect on it either.
>
> So what's the proper way to do this? I suppose I have no choice but to
> redefine the contextMenuEvent for the whole QTreeWidget, but that
> means pushing a whole load of book-keeping from the Leaf
> QTreeWidgetItems up to the tree.
Yes. Redefine the contextMenuEvent for the whole tree.
From that event handler, determine which item you are over
and delegate the rest of the work that item.
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
More information about the Qt-interest-old
mailing list