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. ListView with VisualItemModel
Qt 6.11 is out! See what's new in the release blog

ListView with VisualItemModel

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 3 Posters 4.8k Views 1 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.
  • H Offline
    H Offline
    huluyige
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • H Offline
      H Offline
      huluyige
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        huluyige
        wrote on last edited by
        #3

        Excuse me, i got a solution.

        sorry, it is a very simple question

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Would you mind sharing that simple solution for future reference?

          1 Reply Last reply
          0
          • AlicemirrorA Offline
            AlicemirrorA Offline
            Alicemirror
            wrote on last edited by
            #5

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

            Enrico Miglino (aka Alicemirror)
            Balearic Dynamics
            Islas Baleares, Ibiza (Spain)
            www.balearicdynamics.com

            1 Reply Last reply
            0
            • H Offline
              H Offline
              huluyige
              wrote on last edited by
              #6

              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
              }
              }@

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                Thanks for sharing!

                1 Reply Last reply
                0
                • AlicemirrorA Offline
                  AlicemirrorA Offline
                  Alicemirror
                  wrote on last edited by
                  #8

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

                  Enrico Miglino (aka Alicemirror)
                  Balearic Dynamics
                  Islas Baleares, Ibiza (Spain)
                  www.balearicdynamics.com

                  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