PDA

View Full Version : Get the type of a QTreeWidgetItem



aLiNuSh
24th March 2007, 15:36
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
}
}

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 (http://doc.trolltech.com/4.2/qtreewidgetitem-members.html) and didn't find anything useful.

I hope I made my question clear enough.

Thanks.

aLiNuSh
24th March 2007, 17:18
Just found out, sorry for the useless topic :|


void MyTreeWidget::contextMenuEvent(QContextMenuEvent* event)
{
QTreeWidgetItem* item = itemAt(event->pos());
if (item)
{
// an item exists under the requested position
if (item->parent ()) /* or if (!item->childCount())*/
{
// the item is not expandable
QMenu menu(this);
menu.addAction (chatAction);
menu.exec(event->globalPos());
}
}
else
{
// there is no item under the requested position
}
}

wysota
24th March 2007, 19:44
Item is expandable if it has children, so all you need to do is to check the child count.