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. Need help for a TreeView
Forum Updated to NodeBB v4.3 + New Features

Need help for a TreeView

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
30 Posts 3 Posters 9.5k Views 2 Watching
  • 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.
  • F Fheanor

    I don't have an example that correspond to your example, but these are two examples of how you can use Delegate inside a TreeView.

    • You can use the itemDelegate property of a TreeView . This example will change the color of each line:
    itemDelegate: Rectangle {
           color: ( styleData.row % 2 == 0 ) ? "white" : "lightblue"
           Text {
               anchors.verticalCenter: parent.verticalCenter
               anchors.left: parent.left
               text: styleData.value // this points to the role we defined in the TableViewColumn below; which one depends on which column this delegate is instantiated for.
           }
    }
    
    • You can also define a special Delegate for each column of your TreeView like that:
    TableViewColumn {
           id : someColumn
           role: "someRole"
           title: someRole
           delegate : Rectangle {
               ...
         }
    }
    

    Now you have to play with this to draw what you want

    A Offline
    A Offline
    Arkning
    wrote on last edited by Arkning
    #13

    @Fheanor Ok thanks i'll try I will let you know about my situation. Again thanks for the answers and your time !

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Fheanor
      wrote on last edited by
      #14

      You are welcome :)

      A 1 Reply Last reply
      0
      • F Fheanor

        You are welcome :)

        A Offline
        A Offline
        Arkning
        wrote on last edited by
        #15

        @Fheanor Hi, so I didn't manage to make it work, now just forget about the Rectangle thing, I just want to make a Treeview so can you help me ?

        F 1 Reply Last reply
        0
        • A Arkning

          @Fheanor Hi, so I didn't manage to make it work, now just forget about the Rectangle thing, I just want to make a Treeview so can you help me ?

          F Offline
          F Offline
          Fheanor
          wrote on last edited by
          #16

          @Arkning You need to share what you try to do so we can help you. What is not working when you try to make a TreeView ?
          This example that was linked before works perfectly.

          A 1 Reply Last reply
          0
          • F Fheanor

            @Arkning You need to share what you try to do so we can help you. What is not working when you try to make a TreeView ?
            This example that was linked before works perfectly.

            A Offline
            A Offline
            Arkning
            wrote on last edited by
            #17

            @Fheanor I have some assigning the model value, the example that you gave me the TableViewColumn part work but not the model one, Qt tell me that fileSystemModel doesn't exist. Actually I just want to add some "node" or p"parent" to my Treeview and of course some "children" I suppose it has a link with the model but I don't know how to do it. Hope it is more clear now. Thanks again for your time !

            F 1 Reply Last reply
            0
            • A Arkning

              @Fheanor I have some assigning the model value, the example that you gave me the TableViewColumn part work but not the model one, Qt tell me that fileSystemModel doesn't exist. Actually I just want to add some "node" or p"parent" to my Treeview and of course some "children" I suppose it has a link with the model but I don't know how to do it. Hope it is more clear now. Thanks again for your time !

              F Offline
              F Offline
              Fheanor
              wrote on last edited by
              #18

              @Arkning
              This example is in your QtExample folder.
              Just open your IDE, click on Examples and then write : TreeView. You will see the project.

              A 1 Reply Last reply
              0
              • F Fheanor

                @Arkning
                This example is in your QtExample folder.
                Just open your IDE, click on Examples and then write : TreeView. You will see the project.

                A Offline
                A Offline
                Arkning
                wrote on last edited by
                #19

                @Fheanor I don't have Examples on my IDE... Where should it be on the screen ?

                F 1 Reply Last reply
                0
                • F Offline
                  F Offline
                  Fheanor
                  wrote on last edited by
                  #20

                  You can also create a TreeModel in C++ and then bind it to your Qml TreeView :

                  model: myTreeModel
                  

                  If you don't understand how to bind model and view, have a look on this

                  F 1 Reply Last reply
                  0
                  • A Arkning

                    @Fheanor I don't have Examples on my IDE... Where should it be on the screen ?

                    F Offline
                    F Offline
                    Fheanor
                    wrote on last edited by Fheanor
                    #21

                    @Arkning Do you use QtCreator ? Because there are Examples folders in it.
                    If you don't use it, download and install QtCreator.

                    A 1 Reply Last reply
                    0
                    • F Fheanor

                      @Arkning Do you use QtCreator ? Because there are Examples folders in it.
                      If you don't use it, download and install QtCreator.

                      A Offline
                      A Offline
                      Arkning
                      wrote on last edited by
                      #22

                      @Fheanor Yes I'm using QtCreator

                      F 1 Reply Last reply
                      0
                      • A Arkning

                        @Fheanor Yes I'm using QtCreator

                        F Offline
                        F Offline
                        Fheanor
                        wrote on last edited by
                        #23

                        @Arkning This is on the Welcome page of your IDE... There is an Example Button

                        A 1 Reply Last reply
                        0
                        • F Fheanor

                          @Arkning This is on the Welcome page of your IDE... There is an Example Button

                          A Offline
                          A Offline
                          Arkning
                          wrote on last edited by
                          #24

                          @Fheanor Ok I found it but how can it help me ? I don't see were they create parent or children.

                          1 Reply Last reply
                          0
                          • F Fheanor

                            You can also create a TreeModel in C++ and then bind it to your Qml TreeView :

                            model: myTreeModel
                            

                            If you don't understand how to bind model and view, have a look on this

                            F Offline
                            F Offline
                            Fheanor
                            wrote on last edited by
                            #25

                            @Fheanor said in Need help for a TreeView:

                            You can also create a TreeModel in C++ and then bind it to your Qml TreeView :

                            model: myTreeModel
                            

                            If you don't understand how to bind model and view, have a look on this

                            A 1 Reply Last reply
                            0
                            • F Fheanor

                              @Fheanor said in Need help for a TreeView:

                              You can also create a TreeModel in C++ and then bind it to your Qml TreeView :

                              model: myTreeModel
                              

                              If you don't understand how to bind model and view, have a look on this

                              A Offline
                              A Offline
                              Arkning
                              wrote on last edited by
                              #26

                              @Fheanor The problem is for now I only use Qml I'm not coding in C++ so do you know how to do it in Qml ?

                              F 1 Reply Last reply
                              0
                              • A Arkning

                                @Fheanor The problem is for now I only use Qml I'm not coding in C++ so do you know how to do it in Qml ?

                                F Offline
                                F Offline
                                Fheanor
                                wrote on last edited by Fheanor
                                #27

                                @Arkning I don't know any way to create a TreeModel in Qml, sorry. I think you need to create your model in C++ if you want to use a TreeView

                                A 1 Reply Last reply
                                0
                                • F Fheanor

                                  @Arkning I don't know any way to create a TreeModel in Qml, sorry. I think you need to create your model in C++ if you want to use a TreeView

                                  A Offline
                                  A Offline
                                  Arkning
                                  wrote on last edited by
                                  #28

                                  @Fheanor Ok, anyway thanks for your time I hope I will find how to do it...

                                  1 Reply Last reply
                                  0
                                  • EddyE Offline
                                    EddyE Offline
                                    Eddy
                                    wrote on last edited by Eddy
                                    #29

                                    Hi Arkning,

                                    As Fheanor already suggested, you need to make a model.

                                    To do it in Qt C++ you can follow The simple Tree model example to help you fully understand how it works.

                                    You're lucky because It has been converted to QML

                                    Hope it helps

                                    Eddy

                                    Qt Certified Specialist
                                    www.edalsolutions.be

                                    A 1 Reply Last reply
                                    2
                                    • EddyE Eddy

                                      Hi Arkning,

                                      As Fheanor already suggested, you need to make a model.

                                      To do it in Qt C++ you can follow The simple Tree model example to help you fully understand how it works.

                                      You're lucky because It has been converted to QML

                                      Hope it helps

                                      Eddy

                                      A Offline
                                      A Offline
                                      Arkning
                                      wrote on last edited by
                                      #30

                                      @Eddy Thanks, but I've checked it and It didn't help me out, sorry.

                                      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