How can I control visibilty of a row in a QML TreeView?
-
I would like to control the visibility of a row in a QML TreeView based on model data, say based on data in a particular role.
The only way of doing this appears to be: bind a condition to the RowDelegate's visible property, however it appears to be impossible to access model data from within a TreeView's rowDelegate.
I have exhausted Google. Or vice versa!
The nearest I think I have come is to use the TreeView's currentIndex property (see excerpt below), however when I examine the QModelIndex value received by the model's data() method, it reliably contains the following: QModelIndex(-1,-1,0x0,QObject(0x0)), which is not what I expect to see. Either this is a bug, or a TreeView's rowDelegate should not expect currentIndex to be set...
Any help gratefully received!
Chris.
TreeView { style: TreeViewStyle { ... rowDelegate: Rectangle { property bool isVisible : treeView.isCurrentItemCached() visible: isVisible } } id: treeView ... function isCurrentItemCached() { if (contentManager.content.data(currentIndex, "name") != undefined) { return contentManager.content.data(currentIndex, "name") != “Random String” } else { return false } } }