QML TreeView using only QtQuick 2 works fine?
-
Hi.
Quite a few people, including myself, have been regretting and wondering whyTreeViewis only available inControls 1which are deprecated since Qt 5.12.As it turns out however, it seems quite straight-forward to adapt the
TreeViewcode to depend exclusively on Controls 2 elements.For instance, I just copied and merged all the QML code for a
TreeViewinto a single.qmlfile that only depends on the following imports:import QtQuick 2.15 import QtQuick.Controls 2.15 import QtQml.Models 2.15A working
TreeViewthen only requires a local copy of the originalTableViewColumn.qmlfile (which itself only depends on theQtQuick 2.15module), and a local copy of theQQuickTreeModelAdaptorclass source (which simply implements aQAbstractListModel)Internally, the original
TreeViewusesScrollView,ListViewandFocusScope, all of which have their equivalents inQtQuick2(the only property I needed to comment out was theframeVisibleproperty, which does not exist inScrollView 2, and get rid of theviewportproperty).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.qmlfile 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
filesystembrowserexample using the modifiedTreeViewhere:
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).