[Qt-qml] Tree View In QML
petrus.lundqvist at nokia.com
petrus.lundqvist at nokia.com
Tue Jan 25 08:56:02 CET 2011
"It's not possible"? :)
You can do this in all manners of ways, such as just taking a ListView and making the delegates aware of what node in the tree they are rendering and adjusting the indentation based on that. When a node is expanded or collapsed you just update the list view model accordingly. If you want to keep it 100% QML and JS then the tree view model can e.g. be a JSON structure with a flag for each node that tells the TreeView whether the node is expanded or not.
You can also do it on a lower level by creating a handful of items (essentially tree view delegates) that you place inside a Flickable and move around as the content is scrolled to simulate that there's really one for each node. Then just figure out which nodes of the tree are visible and update the items (tree view delegates) to reflect the correct content. Especially if each node in the tree is rendered with the same height (same delegate height) this is not too hard to do. The result is basically the same as with the ListView.
In any case it's not a great idea to recursively create items for the entire tree (which it sounds like you were trying to do) since this will consume huge amounts of memory and put a very tight limit on the maximum size of tree that your component would be able to support.
Peppe
________________________________________
From: qt-qml-bounces+petrus.lundqvist=nokia.com at qt.nokia.com [qt-qml-bounces+petrus.lundqvist=nokia.com at qt.nokia.com] on behalf of ext Stephen Kelly [steveire at gmail.com]
Sent: Monday, January 24, 2011 21:08
To: qt-qml at qt.nokia.com
Subject: Re: [Qt-qml] Tree View In QML
Ravindra Mitke wrote:
> Hi guys,
>
> I want to create Tree View in Pure QML. I don't want to use QT code into
> that.
> Can you please suggest me the best way about doing this.
>
> Thanks in advance..:)
>
> *Thanks & Regards*
> *Ravindra *
It's not possible. I tried creating one by nesting an Item recursively to
the depth of the tree, but the QML runtime sees that and stops you,
complaining about infinite recursion.
The options are
- Write your own using c++
- Use VisualDataModel and its drill down features.
_______________________________________________
Qt-qml mailing list
Qt-qml at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-qml
More information about the Qt-qml
mailing list