To store custom data in QTreeWidgetItem you should use the setData function
item->setData(0, Qt::UserRole + 1, somedata);
QTreeWidgetItem* item = new QTreeWidgetItem();
QVariant somedata;
item->setData(0, Qt::UserRole + 1, somedata);
To copy to clipboard, switch view to plain text mode
You can then retrieve it with
item->data(0, 0, Qt::UserRole + 1);
item->data(0, 0, Qt::UserRole + 1);
To copy to clipboard, switch view to plain text mode
Or create your items with a user type
and after calling itemAt check the type and cast the object
...
if(item->type() == SOME_USER_TYPE)
{
CustomItem* customitem = static_cast<CustomItem*>(item);
}
QTreeWidgetItem* item = new CustomItem(mTreeWidget, SOME_USER_TYPE);
...
QTreeWidgetItem* item = mTreeWidget->itemAt(some_point);
if(item->type() == SOME_USER_TYPE)
{
CustomItem* customitem = static_cast<CustomItem*>(item);
}
To copy to clipboard, switch view to plain text mode
Bookmarks