[Qt-interest] QTreeView to QTreeWidget at run-time?
Andreas Pakulat
apaku at gmx.de
Tue May 4 20:20:29 CEST 2010
On 04.05.10 12:48:51, Rob Simmermon wrote:
> I've been away from Qt for a few years, and just getting back into it.
>
> Hopefully this is an easy question.
>
> I have a class that inherits from QTreeView, and uses the model/view
> architecture. However, I have a class of utilities written for a
> QTreeWidget, disregarding the model and is only concerned with the View.
>
> 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...
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.
More information about the Qt-interest-old
mailing list