Need help for a TreeView

  • Hi,

    I want to do something like the left part of the picture below (the tree with the yellow rectangle). First to do that I have to use TreeView right ?
    If yes can someone explain me how ? Because I've looked Qt documentation and for TreeView I didn't get it how to use it so If you can help me thanks in advance !

    0_1494939063478_Capture du 2015-09-11 12_21_17.png

  • Moderators


    did you have a look at the QML Treeview docs
    There is an example there.

    The picture you're a referring to is missing in your post. Can you add it? Then we can understand better what you want to do.

  • @Eddy My bad, the picture was on a USB key so it didn't save it ^^. And yes has I said I've looked at the QML TreeView docs and thanks for your answer, hope the picture will be helpful.

  • Moderators

    Hi Arkning,

    Your picture is still missing

    how did you insert it? Did you use a image provider? Then use the following syntax to put it in your post :

     ![alternate text](url)

  • @Eddy I insert it by drag and dropping it.

  • Moderators

    I don't think that will work. Do you see your image after drag and drop?
    At least I don't see it over here.

    please follow the instructions in this link
    to show us your picture, otherwise it will be difficult to help you out.


  • @Eddy Yes I see It (the picture is inside the first message), but It's an image from my computer not from internet so url doesn't work

  • Upload it on internet and share it to us, it will be more easier I think

  • @Fheanor

    I try with an url but it didn't work so here is a link to a photo on google image that show what I want.

  • Looks like you have to use a TreeView with Rectangle Delegate on each line

  • @Fheanor Thanks for the answer do you have a code example ?

  • 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

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

  • You are welcome :)

Log in to reply