mousePressedEvent handler for QTableView
-
I want to handle RMB press events on the viewport and pop a menu when this is done.
When a menu item is chosen, it should apply to all selected rows in the table view.
-
I think I need to sub-class QTableView to achieve this? Or is there a "neat" way to handle this in the owning widget?
-
I want to enable some menu items only if the mouse is over a row of the table (rather than a blank area) - how do I do that?
-
I don't wish to react to RMB on the header, but I think I can just check horizontalHeader()->underMouse() - is that right?
Thanks
David -
-
I want to handle RMB press events on the viewport and pop a menu when this is done.
When a menu item is chosen, it should apply to all selected rows in the table view.
-
I think I need to sub-class QTableView to achieve this? Or is there a "neat" way to handle this in the owning widget?
-
I want to enable some menu items only if the mouse is over a row of the table (rather than a blank area) - how do I do that?
-
I don't wish to react to RMB on the header, but I think I can just check horizontalHeader()->underMouse() - is that right?
Thanks
David-
You can usually achieve event handling without subclassing if you go via
eventFilter(). But as you add functionality to aQTableViewlike this it becomes nicer if sub-classed. I would (think ) would be subclassing to overridecontextMenuEvent(). -
QTableWidgethas anitemAt(). ForQTableViewwhat aboutrowAt(int y)orindexAt(const QPoint &pos)? Check what coordinates the mouse position returns, may have to be mapped to table view, not sure. -
Probably yes, or it may come out in the wash from #2.
-
-
@JonB said in mousePressedEvent handler for QTableView:
contextMenuEvent()
That was what was needed!
Thanks
@Perdrix
In addition to being able to subclass and overridecontextMenuEvent(), there is signal void QWidget::customContextMenuRequested(const QPoint &pos), which does not require subclassing. You choose between event versus signal via setContextMenuPolicy(Qt::ContextMenuPolicy policy) with enum Qt::ContextMenuPolicy.