Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved QML ListView with variable Item heights

    General and Desktop
    2
    4
    1792
    Loading More Posts
    • 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.
    • D
      Dev1337 last edited by Dev1337

      Hi there,

      so i am trying to build a ListView like the Facebook timeline.
      The Items in the ListView should have a variable Item height.

      Is there a way to do this?
      Right now i am using a Column with an Repeater inside but this got a huge performace problem to show more than 50 Objects. ( it gets choppy/slow @ scrolling)

      1 Reply Last reply Reply Quote 0
      • ?
        A Former User last edited by A Former User

        Hi! You need to define your own delegate. See http://doc.qt.io/qt-5/qml-qtquick-listview.html#delegate-prop

        1 Reply Last reply Reply Quote 0
        • D
          Dev1337 last edited by

          My delegate looks like this :

          Item {
          height: text.height + 40px
          Width: 400px

          Text {
          id: text
          Width: parent.Width
          anchors.verticalCenter:parent.verticalCenter
          text: "some random text, but the text can have up to 10 rows so the height is not fix"
          }
          }

          So the ListView can handle Items with a variable height? I thought the ListView needs items with fixed Heights? Or am I wrong?

          1 Reply Last reply Reply Quote 0
          • ?
            A Former User last edited by

            @Dev1337 said:

            So the ListView can handle Items with a variable height?

            Yes, no problem. Take a look at this image: https://drive.google.com/file/d/0B2D1UtsPfTx-aGR4TmxVLWNUX3M/view?usp=sharing. On the left side is a ListView. It has items with a small hight (the ones with black background) and items with variable hight depending on the amount of text they contain. (In this image these text items all have the same hight only because they all contain the same dummy text.)

            1 Reply Last reply Reply Quote 0
            • First post
              Last post