Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QML TreeView using only QtQuick 2 works fine?



  • Hi.
    Quite a few people, including myself, have been regretting and wondering why TreeView is only available in Controls 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 original TableViewColumn.qml file (which itself only depends on the QtQuick 2.15 module), and a local copy of the QQuickTreeModelAdaptor class source (which simply implements a QAbstractListModel)

    Internally, the original TreeView uses ScrollView, ListView and FocusScope, all of which have their equivalents in QtQuick2 (the only property I needed to comment out was the frameVisible property, which does not exist in ScrollView 2, and get rid of the viewport 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.



  • That sounds great. Can you share it via Github?



  • @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 modified TreeView here:
    https://github.com/diracsbracket/qmltreeview2


Log in to reply