Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QtQuick Treeview + PySide6
Forum Updated to NodeBB v4.3 + New Features

QtQuick Treeview + PySide6

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 3 Posters 349 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RynoJ
    wrote on last edited by
    #1

    Good Day

    Im a .Net developer, C# for the past 2 years who decided i want to learn python and the Qt framework. So i would say i have somewhat of an okay skill level.

    Im litterally at the point of giving up on python and Qt. Documentation is extremely confusing, the examples i find is only in c++ which i hardly have much knowledge of.

    ALL I WANT TO DO IS CREATE A TREEVIEW 😭 with a couple columns but it has been a week and i have been able to create some basic treeviews that hardly works.

    I have tried to follow this link but i would like to seperate the UI from my python and qml.

    I am at the point of just resorting to going back to my c# environment of developing this app as i am not doing this professionally but as a hobby.

    What i am aiming for is a treeview that looks like this but with my own data link text

    Any links to guides or more explanatory info would be greatly appreciated

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bob64
      wrote on last edited by Bob64
      #2

      I have no experience with Python and Qt but I just wanted to check something. You have posted in the QML area and you mention QML in your post, but the link you mentioned is using Qt Widgets. Qt supports two different approaches to GUIs: Widgets and QML. Generally speaking, you choose one and stick with it. (At a more advanced level, it is possible to embed QML in a Widgets app but not vice versa.)

      In principle, QML does provide the good UI separation that you want.

      Unfortunately TreeView is probably one of the hardest components to get going with because, unlike ListView for example, there are no simple built-in models that you can use to get started with. You pretty much have to implement a QAbstractItemModel from the outset. It is further complicated by most documentation being geared towards C++, and also by the TreeView in Qt 6 not being the same as the TreeView in previous releases, which means you have to be careful if using older information.

      I would break it down as follows:

      • Maybe start with a simpler view like a ListView populated from a ListModel purely in QML.
      • Then learn how to replace the ListModel with a model provided from your Python backend. This will be an implementation of a QAbstractListModel.
      • Once you are comfortable with how this works, look at implementing a QAbstractItemModel to support a TreeView. Although TreeView itself has changed, the way you implement the backend model should be stable so you don't need to worry about looking at older guides for this.
      • If you can successfully implement the model, the QML for the TreeView should be relatively straightforward. For guidance on the QML side, you should be able to adapt examples based on a C++ backend as QML is agnostic as to whether this is C++ or Python.
      R 1 Reply Last reply
      1
      • B Offline
        B Offline
        Bob64
        wrote on last edited by Bob64
        #3

        I found this example of implementing a tree model in Python. I believe it is an adaptation of one of the standard examples. Note that this is targeting Qt Widgets but the same model could be used to drive a QML TreeView.

        1 Reply Last reply
        1
        • B Bob64

          I have no experience with Python and Qt but I just wanted to check something. You have posted in the QML area and you mention QML in your post, but the link you mentioned is using Qt Widgets. Qt supports two different approaches to GUIs: Widgets and QML. Generally speaking, you choose one and stick with it. (At a more advanced level, it is possible to embed QML in a Widgets app but not vice versa.)

          In principle, QML does provide the good UI separation that you want.

          Unfortunately TreeView is probably one of the hardest components to get going with because, unlike ListView for example, there are no simple built-in models that you can use to get started with. You pretty much have to implement a QAbstractItemModel from the outset. It is further complicated by most documentation being geared towards C++, and also by the TreeView in Qt 6 not being the same as the TreeView in previous releases, which means you have to be careful if using older information.

          I would break it down as follows:

          • Maybe start with a simpler view like a ListView populated from a ListModel purely in QML.
          • Then learn how to replace the ListModel with a model provided from your Python backend. This will be an implementation of a QAbstractListModel.
          • Once you are comfortable with how this works, look at implementing a QAbstractItemModel to support a TreeView. Although TreeView itself has changed, the way you implement the backend model should be stable so you don't need to worry about looking at older guides for this.
          • If you can successfully implement the model, the QML for the TreeView should be relatively straightforward. For guidance on the QML side, you should be able to adapt examples based on a C++ backend as QML is agnostic as to whether this is C++ or Python.
          R Offline
          R Offline
          RynoJ
          wrote on last edited by
          #4

          @Bob64

          Thank you very much for your informative explanation.

          Now that you mention that the link refers to widgets, i clearly see it. The documentation is a little confusing sometimes and not super clear if you are not very familiar with the Qt framework i think.

          I will definitely make use of your advice in using the ListView model and the link you have provided.

          Thank you very much

          JonBJ 1 Reply Last reply
          0
          • R RynoJ has marked this topic as solved on
          • R RynoJ

            @Bob64

            Thank you very much for your informative explanation.

            Now that you mention that the link refers to widgets, i clearly see it. The documentation is a little confusing sometimes and not super clear if you are not very familiar with the Qt framework i think.

            I will definitely make use of your advice in using the ListView model and the link you have provided.

            Thank you very much

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @RynoJ
            Two observations:

            • C# is a lot closer to C++ than to Python, which is a completely different language.

            • QML is a declarative language, and not really a programming language. Quite different from normal procedural programming like C# (or for that matter C++ or Python). It is a totally different paradigm. Depending on what you did in C# about e.g. the UI, using Qt widgets (with either C++ or Python) would likely be a lot closer than anything QML.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved