PDA

View Full Version : Right Click in QTableView



admkrk
28th April 2017, 02:07
I am using activated() to open a file in one of my columns, but that only works with the enter key. The only way I could find to allow using a mouse was to subclass QTableView and use mousePressedEvent(). This seems to be working, but it also seems too simple, and I am unsure if I did it right, or if I should not have done something more. All I did was:

void TableView::mousePressEvent(QMouseEvent *event)
{
QPoint pos = event->pos();
QPersistentModelIndex index = indexAt(pos);

if(event->button() == Qt::RightButton)
emit activated(index);
else
QAbstractItemView::mousePressEvent(event);
}
Is that the proper way to do it?

Santosh Reddy
3rd May 2017, 05:42
That is enough.

admkrk
3rd May 2017, 10:56
Thanks for the conformation. I think I have this part of my application roughed out enough to move on, and have started the next part.