View Full Version : QTableView context menu

17th October 2007, 16:47
I want to show a context menu on a QTreeView. The function that the QTreeView provide is customContextMenuRequested(const QPoint &) Do you know any method in which I could decide if the user clicked on an item or on the empty space? The QTreeWidget control has a function for that itemAt(QPoint). Does QTreeView have something like that? Thanks a lot. I am pretty new to QT.

17th October 2007, 16:52
No, but in the slot connected to customContextMenuRequested you can check the model index returned by QTreeView::indexAt.

17th October 2007, 19:10
My mistake. Not QTreeView i am using QTableView.

17th October 2007, 19:24
Same thing. Both QTableView and QTreeView are subclasses of QAbstractItemView, which exposes indexAt().

17th October 2007, 19:36
Thanks a lot. I was looking for function named itemAt() :)

17th October 2007, 19:40
The views are model based so you want the model index in this case. If it is valid the you clicked on an item.