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

ListView with VisualItemModel



  • Hi everyone,

    I'm using a VisualItemModel for a listView. for example

    @ListView{
    id:myList
    height:??????
    width:360
    model:myModel
    }
    VisualItemModel{
    id:myModel
    Rectangle{
    id:myRec
    width:360
    height:40
    }
    }@

    As you can see above, i want the list view'height is equal to the model's height, specially to the myRec'height(40), in the example.

    So my question is : how can we do a property binding between a listView and its VisualItemModel?

    Thanks in advance



  • further question is: how can i do it if the model is in another qml. that's to say, i use

    @model: VisualItemModel{}@

    to intialize listView's model.



  • Excuse me, i got a solution.

    sorry, it is a very simple question



  • Would you mind sharing that simple solution for future reference?



  • Andre, you are great!!! Wrote what I was writing :)



  • yes,

    in the VisualItemModel.qml, we add a property to the model
    @VisualItemModel{
    id:myModel
    property real myHeight:myRec.height
    Rectangle{
    id:myRec
    width:360
    height:40
    }
    }@

    and in the view.qml, we create an instance of visualItemModel, and bind the two heights
    @ListView{
    id:myList
    height:myModel.myHeight
    width:360
    model:myModel
    VisualItemModel{
    id:myModel
    }
    }@



  • Thanks for sharing!



  • Thanks! I am doing some stuff on lists and it is almost useful as an example.


Log in to reply