[Qt-interest] QtreeWidget and right-click

Andreas Diehl Andreas_Diehl at abs.org
Fri Mar 27 13:35:28 CET 2009


Hello.

You can overwrite contextMenuEvent(QContextMenuEvent* e) in your QTreeWidget class and show a custom QMenu. To find the QTreeWidgetItems that are affected you can call
 QTreeWidget::selectedItems()  or
 QTreeWidget::itemAt(const QPoint &p) and give it the point from the event, like:

void MyTreeWidget::contextMenuEvent(QContextMenuEvent* event)
{
   QTreeWidgetItem*        item;
   QList<QTreeWidgetItem*> selected = this->selectedItems();
   if (selected.isEmpty())
     item = this->itemAt( event->pos() );

   //show QMenu
   //do s.th. with the items
} 

Read the QMenu API for more informations on how to show it as a context popup. QMenu::exec(...) looks fine.

Regards,
	Andreas


-----Ursprüngliche Nachricht-----
Von: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] Im Auftrag von NARCISO, Rui
Gesendet: Freitag, 27. März 2009 11:53
An: Qt Interest (E-mail)
Betreff: [Qt-interest] QtreeWidget and right-click


Hi all

I'm a bit new to Qt.
I've successfully put in place an app based on a QTreeWidget and now I'd like to be able to right-click on any (or several) QtreeWidgetItems and have a menu appear with several actions.

How to go about doing this ?

Rui

The information in this e-mail is confidential. The contents may not be disclosed or used by anyone other then the addressee. Access to this e-mail by anyone else is unauthorised.
If you are not the intended recipient, please notify Airbus immediately and delete this e-mail.
Airbus cannot accept any responsibility for the accuracy or completeness of this e-mail as it has been sent over public networks. If you have any concerns over the content of this message or its Accuracy or Integrity, please contact Airbus immediately.
All outgoing e-mails from Airbus are checked using regularly updated virus scanning software but you should take whatever measures you deem to be appropriate to ensure that this message and any attachments are virus free.


_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
--
Mit freundlichen Grüßen
Andreas Diehl 
 
-------------------------- ABS -------------------------
ABS Systemberatung OHG          Tel: +49 (0)7053/9290-03
Hauffstr. 9                     Fax: +49 (0)7053/9290-
D-75385 Bad Teinach-Zavelstein        http://www.abs.org
Registergericht Calw HRA 1031
[mailto:Andreas_Diehl at abs.org]
 
----- Loesungen fuer den Maschinen- und Anlagenbau -----




More information about the Qt-interest-old mailing list