QML TreeView using only QtQuick 2 works fine?
-
Hi.
Quite a few people, including myself, have been regretting and wondering whyTreeView
is only available inControls 1
which are deprecated since Qt 5.12.As it turns out however, it seems quite straight-forward to adapt the
TreeView
code to depend exclusively on Controls 2 elements.For instance, I just copied and merged all the QML code for a
TreeView
into a single.qml
file that only depends on the following imports:import QtQuick 2.15 import QtQuick.Controls 2.15 import QtQml.Models 2.15
A working
TreeView
then only requires a local copy of the originalTableViewColumn.qml
file (which itself only depends on theQtQuick 2.15
module), and a local copy of theQQuickTreeModelAdaptor
class source (which simply implements aQAbstractListModel
)Internally, the original
TreeView
usesScrollView
,ListView
andFocusScope
, all of which have their equivalents inQtQuick2
(the only property I needed to comment out was theframeVisible
property, which does not exist inScrollView 2
, and get rid of theviewport
property).Aside from the styling parts which I either eliminated or hard-coded,
and the scrollbar code which I currently disabled, it seems to work just fine: the tree displays, expands/collapses and behaves as expected, so far.I wanted to upload the code for that self-contained
TreeView.qml
file here, but unfortunately, posts are not allowed to be that long. -
@mnesarco said in QML TreeView using only QtQuick 2 just works fine?:
Can you share it via Github?
I uploaded the
filesystembrowser
example using the modifiedTreeView
here:
https://github.com/diracsbracket/qmltreeview2 -
A questions: Is it possible to make a copy of QQuickTreeModelAdaptor in a LGPL licensed program or would this violate the LGPL?
@maxwell31 What exactly do you mean? Do you want to modify QQuickTreeModelAdaptor? Or why else you would need to "copy"?
If you want to modify QQuickTreeModelAdaptor then you have ot make your changes open source (LGPL requirement).