{
if (item)
{
// an item exists under the requested position
menu.addAction (chatAction);
menu.exec(event->globalPos());
}
else
{
// there is no item under the requested position
}
}
void MyTreeWidget::contextMenuEvent(QContextMenuEvent* event)
{
QTreeWidgetItem* item = itemAt(event->pos());
if (item)
{
// an item exists under the requested position
QMenu menu(this);
menu.addAction (chatAction);
menu.exec(event->globalPos());
}
else
{
// there is no item under the requested position
}
}
To copy to clipboard, switch view to plain text mode
I've subclassed QTreeWidget in order to create a context menu and what I want to do is to exclude some commands from the context menu in case an item from the tree is expandable. Like I have an item that's a group and its subitems are users and I don't want to have the option "Rename" on the user item but I want it on the group item.
So is there like a item->isExpandable () method, or is there any way I could implement something like that? I know there's a isExpanded () method but it checks whether the item is expanded not expandable.
I've checked here and didn't find anything useful.
I hope I made my question clear enough.
Thanks.
Bookmarks