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. [SOLVED]: ListView spacing
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]: ListView spacing

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 2 Posters 2.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.
  • _ Offline
    _ Offline
    _Mark_
    wrote on last edited by
    #1

    Hi,
    it seems the "spacing" property of the ListView component actually set the spacing between each item. Instead I want to set the distance from the center of them - no matter of their width.

    Is there a simple way to achieve this?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Make the delegate have 0 width, and create "real" item as its' child, but this time give it the width you desire.

      (Z(:^

      1 Reply Last reply
      0
      • _ Offline
        _ Offline
        _Mark_
        wrote on last edited by
        #3

        So I tried the following:

        @
        Component {
        id: modelDelegate
        Item {
        width: 0
        anchors.verticalCenter: parent.verticalCenter
        Text {
        anchors.verticalCenter: parent.verticalCenter
        anchors.horizontalCenter: parent.horizontalCenter
        text: value
        width: 100
        }
        }
        }
        @

        But changing the width of the child (the Text component) leads to change the position of the items.
        Perhaps I miser-understood your hint?

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          I think you understood well. Maybe my hint was not so good ;-) Try bumping the width to 1 - QMl engine might misinterpret width 0 as "invisible".

          @
          delegate: Item {
          height: 1
          width: 1

          Text {
          anchors.centerIn: parent
          text: value
          width: 100
          }
          }
          @

          (Z(:^

          1 Reply Last reply
          0
          • _ Offline
            _ Offline
            _Mark_
            wrote on last edited by
            #5

            I think I found the problem. It works until the items overlap each other. But I can live with this "feature"!

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              Yes, that will not take item collision into account, as we are fooling the ListView into thinking that the item is very small, when in reality it is not.

              (Z(:^

              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