[Qt-interest] QTreeView to QTreeWidget at run-time?

Mandeep Sandhu mandeepsandhu.chd at gmail.com
Wed May 5 10:06:45 CEST 2010


>> So my question, that I can't seem to find the answer to after many hours of
>> searching, is how do I copy all the items and their current states from the
>> QTreeView to a QTreeWidget, disregarding the model completely.
>>
>> I was looking for some type of default copy constructor that would do this,
>> but can't find one.
>
> With a model there's no such thing as an "item", at least not as a
> self-contained object. Your model might internally use such items, but
> then you should already know how to get at them...

QStandardItemModel does contain QStandardItem which hold the actual
data. And it also provides a way to get them with either a row/col of
with a model index.

Though the OP did not mention what model is being used in his
app...but as Andreas said you can get the rowCount and columnCount of
your model and extract all data by iterating over it.

HTH,
-mandeep

>
> To transfer some or all of the data in your model you could create a
> loop that runs over all rows+columns and fetches an index for each
> combination, then creates a QTreeWidgetItem and sets the text, icon,
> etc. by using the model's data() function. With a real tree structure
> you'll also want to check wether there are any children and then do the
> same on the child list too.
>
> Andreas
>
> --
> You will probably marry after a very brief courtship.
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>



More information about the Qt-interest-old mailing list