How do you simulate a tree view in Qt Quick since it's not included in Controls 1.0?
-
[quote author="loran" date="1393348350"]Unfortunately the example above crashes when I remove any element from the model when the folder in the view is expanded. Tested with Qt 5.2.0 and 5.2.1 on Linux. ...
[/quote]With the current snapshot of Qt5.3-RC the crash does not happen any more. I get a message on the console: "TreeView.qml:15: TypeError: Cannot read property 'text' of null"
-
I am trying to make this (really nice) view work with a QAbstractItemModel but I'm pretty much stuck -.-
My first approach was to return the childItems of a node as model. I wrote a constructor in my model (of type QAbstractListModel) that took a QList<Node*> and returned a new model whenever the view wanted the subnodes of a node. This worked really well for read-only access, but is a mess regarding editing the tree, since I guess the models do not communicate to each other and a model has no idea what happens in another model. So if you delete a node in one model and another model wants to access the children of this model the whole thing crashes, because it does not know there is one node missing (that is my guess at least)
So it seems the only solution for a consistent model is to have only one model that keeps track of every event that happens in the tree. So my second approach was the following: I returned the childnodes of a node as a QList<Node*> and made the data of a node accessible through the Q_PROPERTY macro, e.g. Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged). But now the view does not work anymore because the data of a QObject based model can only be accessed with model.modelData.role and not with model.role like in a QAbstractItemModel. The view would have to deal with two kinds of models and I do not know how to realize this.
Can maybe anybody give me a hint on how I could make this work, it would be very much appreciated. Thank you.
edit: I just realized the second approach would not work anyhow since the view would not be updated in a QObject based model.
-
If you want to make your own Qt Quick TreeView in C++, there's a presentation here:
https://www.qtdeveloperdays.com/sites/default/files/north-america/QtQuickTreeView.pdf -
If you want to make your own Qt Quick TreeView in C++, there's a presentation here:
https://www.qtdeveloperdays.com/sites/default/files/north-america/QtQuickTreeView.pdf -
[quote author="Jens" date="1381914126"]Here is an updated example using qt quick controls:
...[/quote]
A very nice example. It seems like it's not that easy to implement key-events(up, down, ...) for controling this view. I would appreciate it if anyone could come up with an idea.
-
[quote author="Jens" date="1381914126"]Here is an updated example using qt quick controls:
...[/quote]
A very nice example. It seems like it's not that easy to implement key-events(up, down, ...) for controling this view. I would appreciate it if anyone could come up with an idea.
-
If you can wait a bit longer, there will be an official TreeView QML type in the upcoming "Qt 5.5 release":http://blog.qt.io/blog/2015/02/05/licensing-of-new-modules-in-qt-5-5/
-
If you can wait a bit longer, there will be an official TreeView QML type in the upcoming "Qt 5.5 release":http://blog.qt.io/blog/2015/02/05/licensing-of-new-modules-in-qt-5-5/