A QtQuickControls2 based TreeView
This repository contains the sources for a QtQuickControls2 based TreeView control that you can use in your qml desktop application.
This user control is in alpha version. There are some missing features or things that do not work yet:
QtQuickControls2 do not provide a TreeView control yet because they focus on mobile application development where tree view are not that common. But QtQuickControls2 can also be used to develop nice desktop applications and a tree view component is often needed. I needed a TreeView for one of my personal (but still private) project so I decided to create a one myself.
The solution I found is to use a ListView Item as the base qml item of the tree view and use a proxy model that flatten a source tree model.
The core of the library can be found in the lib
folder. This is a header only library that contains the TreeViewModel
and the TreeItemViewModel
The imports
directory contains the qml implementation of the TreeView and the TreeItemView.
The TreeItemView delegate is extensible: you can specify the component to use to to render both the arrow and the display items.
It handles indentation and expanding/collapsing of nodes automatically for you.
There is also a small tests
suite (using the catch testing framework ) that you can run using ctest
.
The example
create two tree model: a StandardItemModel
and QFileSystemModel
. It then wraps those two models in a
TreeViewModel
and exposes them via a context property.
License here is "super-open", not even copy-left or copy-right, just use it as you want, as it's the most practical to you: