Creating popup menu in Qt for QTableView
14,722
Check out the customContextMenuRequested signal to get the event, and use a QMenu for the menu itself. Use QTableView::indexAt to find out what, if any, cell was clicked based on the coordinates given to the signal and take the appropriate action when a menu item is clicked.
Comments
-
Donotalo about 2 years
I have a
QTableView
in the main UI of my program. I'd like to show popup menu when user right clicks on the cells of the table and take appropriate action when an option is selected from the menu.I am using Qt Creator 1 (Qt version 4.5). How can I do that?
-
David Souther over 14 yearsYou will need to call menu.exec(const QPoint&) to display it. Make sure you translate it to the appropriate coordinates: menu.exec(mapToGlobal(point), 0)
-
RushHour almost 14 yearsOr just use menu.exec(QCursor::pos()) doc.trolltech.com/latest/qmenu.html#exec
-
trig-ger over 6 yearsContext menu may be called from the keyboard shortcut, so cursor position is not always the correct point of call.