[PyQt] Re: problem with QAbstractItemModel
Vicent Mas
uvemas at gmail.com
Sat Nov 7 10:02:45 GMT 2009
On 2009-11-07 Linos <info at linos.es> said:
> ...
> Hi,
> in the qt examples from qt 4.5 documentation you can see they use this in
> the model:
> http://doc.trolltech.com/4.5/itemviews-simpletreemodel-treemodel-cpp.html
>
> QModelIndex TreeModel::index(int row, int column, const QModelIndex
> &parent) const
> {
> if (!hasIndex(row, column, parent))
> return QModelIndex();
>
> TreeItem *parentItem;
>
> if (!parent.isValid())
> parentItem = rootItem;
> else
> parentItem = static_cast<TreeItem*>(parent.internalPointer());
>
> TreeItem *childItem = parentItem->child(row);
> if (childItem)
> return createIndex(row, column, childItem);
> else
> return QModelIndex();
> }
>
Thanks for this info. I simply didn't check this page because I was interested
in editable models not in read-only models. Its funny to see that index method
implementation in the read-only example is more complex than in the editable
one.
But still, it is nearly the same workaround provided by Baz and doesn't answer
my question about validity of the passed row argument.
> and this in the item class.
> http://doc.trolltech.com/4.5/itemviews-simpletreemodel-treeitem-cpp.html
>
> TreeItem *TreeItem::child(int row)
> {
> return childItems.value(row);
> }
>
> but they can do this because QList .value method dont get an error if it is
> out of bounds.
Yes but, as you can see in the in the index method provided in that example,
this is called *after* the row argument has been validated so it has no impact
in my question.
Vicent
::
Share what you know, learn what you don't
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20091107/933b29b9/attachment.bin
More information about the PyQt
mailing list