[Qt-interest] QModelIndex from internal pointer in QAbstractItemModel
Volker
volker at openbios.org
Fri Nov 12 17:49:19 CET 2010
On Friday 12 November 2010 17:25:53 Simon Drouin wrote:
> Hi all,
>
> I have a custom tree structure that I want to show in a QTreeView. I store
> the elements of the tree (pointers to MyTreeItem in the example bellow) in
> the internal pointer of QModelIndex. Now, how do I get the QModelIndex that
> contains a specific element of my tree. I other words:
>
> MyTreeItem * item;
> QModelIdex index = ItemToIndex( item );
>
> how do I implement the ItemToIndex function?
Calculate the item's row below its parent in your tree. Also its column, if your tree is multi columed.
Then call createIndex( row, column, (void*)item ) to get a QModelIndex
More information about the Qt-interest-old
mailing list