PDA

View Full Version : right click in TableView?



nategoofs
14th August 2007, 06:24
How would I add a rightClick function to a QTableView with a subclassed QAbstractTableModel? Currently, I have (and would like to replace) a Q3Table with Q3Popupmenu connected through a mousepressed signal from Q3Table.

Thanks!

jpn
14th August 2007, 06:32
Reimplement QWidget::contextMenuEvent(). You can get the item (if any) at requested position with QContextMenuEvent::pos() and QAbstractItemView::indexAt(), more or less like:


void MyTableView::contextMenuEvent(QContextMenuEvent* event)
{
QModelIndex index = indexAt(event->pos());
if (index.isValid())
{
// ...
}
}
There are also alternative ways of handling context menu. See QWidget::contextMenuPolicy (http://doc.trolltech.com/4.3/qwidget.html#contextMenuPolicy-prop) for more details.