Important: Please read the Qt Code of Conduct -

ListView: Auto width based on content width

  • Hello,

    I am using a list view to represent a set of elements. These elements are added once the list view component has been completed. The list view has a delegate that is a RowLayout with two items inside: one Text and one ToolButton. These RowsLayout's don't have a fixed width, neither a fixed height. Consequently, I'd like to not have to hardcode a "width" properties in my ListView element.

    So I did this:

    ListView {
                height: parent.height
                implicitWidth: contentItem.childrenRect.width
                id: listView

    But even doing this, I have the feeling the width is wrongly computed (cause of the position of my scrollbar that is not just on the right of my list view, but far far away, as if it was the scroll bar of my entire application).

    Thank you to anyone who has the answer to this problem!

Log in to reply