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. [QML List View] Implicit width

[QML List View] Implicit width

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 1.8k 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.
  • mistralegnaM Offline
    mistralegnaM Offline
    mistralegna
    wrote on last edited by
    #1

    Hi,

    I would like to know if it is possible to create a ListView component with a width that will be automatically computed from its children width.

    For instance:

        SplitView {
            id: splitView
            x: 0
            y: 0
            anchors.fill: parent
    
            ListView {
                id: listView
                // width: implicitWidth ?
                // implicitWidth: childrenRect.width?
                height: parent.height
    
                model: ListModel {
                    ListElement {
                        name: "Grey"
                        colorCode: "grey"
                    }
    
                    ListElement {
                        name: "Red"
                        colorCode: "red"
                    }
    
                    ListElement {
                        name: "Blue"
                        colorCode: "blue"
                    }
    
                    ListElement {
                        name: "Green"
                        colorCode: "green"
                    }
                }
                delegate: Item {
                    x: 5
                    // Which width here ?
                    // width: implicitWidth
                    height: 40 // This may not always be 40
                    Row {
                        id: row1
                        Rectangle {
                            width: 40 // This may not always be 40
                            height: 40 // Same as above
                            color: colorCode
                        }
    
                        Text {
                            text: name
                            font.bold: true
                            anchors.verticalCenter: parent.verticalCenter
                        }
                        spacing: 10
                    }
                }
            }
    
            Rectangle {
                id: rect
                color: "blue"
                anchors.left: listView.right
                anchors.right: parent.right
            }
        }
    

    Thank you in advance for your answers !

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qnope
      wrote on last edited by
      #2

      Using Listview.contentWidth is not enough?

      1 Reply Last reply
      0
      • mistralegnaM Offline
        mistralegnaM Offline
        mistralegna
        wrote on last edited by
        #3

        Likle this:

                ListView {
                    id: listView
                    width: ListView.contentWidth
                    height: ListView.contentHeight
                    ...
              }
        
        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