PDA

View Full Version : How to detect theright clicked item when using customContextMenuRequested signal



umen
22nd October 2010, 23:35
hello all
quick question
im using in Treewidget the customContextMenuRequested signal and using using popup with qmenu
How can I get the item pointer / object / reference that just bean right clicked before the pop up executed
I need to make some validation on the item

wysota
23rd October 2010, 00:59
QTreeWidget::itemAt() returns a pointer to an item in a specific point relative to the widget's top-left corner. Remember the widget is probably the view's viewport and not the view itself.

umen
23rd October 2010, 14:12
one problem remains when i right click not on tree node i still trigger the customContextMenuRequested SLOT function , how can i check there is its QTreeWidgetItem object?

wysota
23rd October 2010, 14:13
I don't understand. If you click outside any item then the returned pointer will be null.

umen
23rd October 2010, 14:16
found i think the answer
QModelIndex index = this->indexAt(pos);
then in the code..
if(index.isValid()) .....

wysota
23rd October 2010, 14:17
You're using item based approach, so:

QTreeWidgetItem *item = indexAt(pos);
if(item) {
// item is valid
}