Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QML listview spacing problem
QtWS25 Last Chance

QML listview spacing problem

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
3 Posts 3 Posters 2.4k Views
  • 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.
  • C Offline
    C Offline
    Chobin
    wrote on last edited by Chobin
    #1

    Hallo,

    I want to build a listview where there are some rectangles and a space between them. Not all rectangles are visible, but it depends on the application setting. Whene a rectangle is not visible, the listview continues properly without holes.
    My code is below:

    ListView {
        id: rowList
        visible: rowVisible
        anchors.left: parent.right
        anchors.leftMargin: 1
        anchors.top: nameList.bottom
        anchors.topMargin: 2
        width: 1280* 0.751
        height: nameList.height/5
        orientation: ListView.Horizontal
        spacing: 1
    
        model: rowModel
    
        delegate  Rectangle {
                width: cellWidth
                height: nameList.height/5
                color: cellColor
                anchors.left: parent.left
                border.width: 1
                border.color: "white"
                visible: cellVisible
                Text {
                    color: "red"
                    text:"Test"
                    font.capitalization: Font.AllUppercase
                    font.pixelSize: 20
                    verticalAlignment: Text.AlignVCenter
                    wrapMode: Text.WordWrap
                    anchors.fill: parent
                    font.weight: Font.Normal
                    horizontalAlignment: Text.AlignHCenter
                    font.family: helveticaCondensed.name
                }
            }
    }
    

    P.S: the "nameList" is another listview on the top of the current listview.

    The listview takes the following data cellWidth, cellColor, cellVisible from a C++ model ("rowModel").
    The C++ model calcolates the cellWidth parameter in the following way: it divides the listview width for the cell number visible.
    The final result is that sometimes the spacing between two consecutive rectangoles is not the same.

    Does someone help me to solve the problem?

    Many Thanks in advance for your support.

    Best Regards,
    Chobin

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vladstelmahovsky
      wrote on last edited by
      #2

      set delegate's height to 0 when delegate not visible

      1 Reply Last reply
      0
      • Camilo del RealC Offline
        Camilo del RealC Offline
        Camilo del Real
        wrote on last edited by
        #3

        Hi @Chobin , as @vladstelmahovsky said, you must to set the delegate's sizes, but your listview is horizontal, so you must set his width to 0 if cellVisible is false, on the other hand, if the listview's orientation is vertical you must set the height.
        The listview dont use strict sizes for delegates, but it reserve the space that the component requires, and the listview dont use the visible property to relayout the content, therefore we must change the delegate size for relayout the listview content and really to hide the delegate
        You can use animation behavior to achieve a nice effect

        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