[Qt-qml] hasChildren attribute for Qml Model?

Stephen Kelly steveire at gmail.com
Tue Apr 20 11:56:17 CEST 2010


Martin Jones wrote:

> On Mon, 19 Apr 2010 10:09:17 pm ext Stephen Kelly wrote:
>> In QTreeView, that's a [+] which you can click to expand.
> 
> You could add a Q_INVOKABLE method to your model to get the child count,
> similar to the setRoot() method in this example:
> 
> http://qt.nokia.com/doc/4.7-snapshot/qml-visualdatamodel.html#rootIndex-
prop
> 
> 

Indeed, however, it gets complicated when an intermediate proxy model 
filters out all the children. 

That is common in my case because it is something like a filesystem where on 
one side is the folder structure and on the other side is the files in the 
selected folder. In the view that is showing only the folder structure, 
hasChildren is true only if it has subfolders. Files are already filtered 
out. 

First I put a method similar to what you describe in the proxy actually sent 
into the qml environment, but then when I added another proxy I had to move 
the logic to that class. That's not a good solution.

Currently I have an invokable method in a globally accessible application 
object to figure out if the correct proxy hasChildren at a particular row. 
The method will have to be updated if ever the application changes. It's a 
bit too much magic for me, so the best place for a solution is further down 
the stack in Qt.

All the best,

Steve



More information about the Qt-qml mailing list