tags:

views:

232

answers:

2

I'm trying to add a context (right click) menu to a Qt QListView. I see in Qt 3.3 there is "contextMenuRequested" (which I could use) - http://doc.trolltech.com/3.3/qlistview.html#contextMenuRequested. However, I can't see such a method in Qt4. Does anyone know how to add a context menu to a QListView?

+1  A: 

I don't know why the signal has been removed but it's still a QWidget so you can always override

void QWidget::contextMenuEvent ( QContextMenuEvent* );

or

void QWidget::customContextMenuRequested( const QPoint& pos );

depending on your context menu policy setting for the widget.

Troubadour
customContextMenuRequested() is a signal, not an overridable function
Harald Scheirich
+1  A: 

I don't know what you are trying to accomplish but you can easily add a context menu to any widget by calling QWidget::AddAction(QAction*) with the actions that you want to add to your context menu and setting the context menu policy

widget->setContextMenuPolicy(Qt::ActionsContextMenu);

the widget will prepare and show the context menu, all you need to do is hook up the actions triggered() signals to the appropriate handlers

Harald Scheirich