MyCustomStandardItem and hidden data...
Hi,
I'm trying to implement MyCustomStandardItem (inherited from QStandardItem) which has to contain some standard data (i.e. QString, QIcon, etc.) to visualize in a tree view and a list of events associated to the item (QList<Event>, where --> typedef QPair<QDataTime, int> Event) to not visualize in the same tree view...
Now...I want to visualize the list of events associated to each item through a tootip but I have some problem to retrieve the item events list starting from the item index...I try this solution:
MyCustomStandardItem* item = static_cast<MyCustomStandardItem*>(itemIndex.inter nalPointer());
item != NULL, but it crash just after a call an item member function.
Re: MyCustomStandardItem and hidden data...
That is because QModelIndex::internalPointer() "[r]eturns a void * pointer used by the model to associate the index with the internal data structure" and there is no way to tell what that internal structure is; in my opinion you should not be using this function. I suspect QStandardItemModel::itemFromIndex() might be what you are looking for.
Re: MyCustomStandardItem and hidden data...
Instead of creating MyCustomStandardItem I would recommend you use QStandardItem's built in mechanisms for custom data.
The data can then be retrieved with
To draw the items properly in your widget create a custom QItemDelegate or QStyledItemDelegate
You also mention you are using a tree view. Consider QTreeWidget then you can use QTreeWidgetItemIterator to iterate over all of the items and extract data from them.
Re: MyCustomStandardItem and hidden data...
Quote:
Originally Posted by
Berryblue031
Instead of creating MyCustomStandardItem I would recommend you use QStandardItem's built in mechanisms for custom data.
The data can then be retrieved with
To draw the items properly in your widget create a custom QItemDelegate or QStyledItemDelegate
Thanks...it's the solution that I chose!