List into column



  • then i adding list to column there is an error:
    QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column. Column will not function.

    ListView becomes colapsed into 0px line.

    simlified layout:
    @
    Column {
    anchors.fill: parent
    Button {
    id: topBtn
    }
    ListVeiw {
    height: parent.height - topBtn.height - bottomBtn.height
    }
    Button {
    id : bottomBtn
    }
    }
    @

    In Qt Widgets Listview expands height automaticaly.

    ps. sory for my english ;)



  • Your simplified example is not enough to reproduce the issue and would not cause this warning. Most likely you have anchors declared inside button or some other part of your code.

    The modified example below works fine:

    @
    import QtQuick 2.0

    Rectangle {
    width: 360
    height: 360
    Column {
    anchors.fill: parent
    Rectangle {
    id: topBtn
    width: parent.width ; height: 20
    color: "red"
    }
    ListView {
    height: parent.height - topBtn.height - bottomBtn.height
    width: parent.width
    model: 20
    delegate: Text { text: modelData}
    }
    Rectangle {
    id : bottomBtn
    width: parent.width ; height: 20
    color: "blue"
    }
    }
    }

    @



  • @
    height: parent.height - topBtn.height - bottomBtn.height
    @
    if add two lists, how can i compute height?
    or if i hide buttons? so i want automaticaly computed height, such as in widgets.

    any workaround?



  • You probably do not want to use a ListView if you want a fixed height column that resizes to content. ListView is for flickable content that is larger than your screen.

    Instead you can use a Repeater like this.

    @
    Column {
    Repeater {
    model: 20 (or any other list model)
    SomeDelegateItem {}
    }
    }
    @



  • In this way i lose flickable, scroll conditions.
    if put repeater in Flickable - it will be colapsed as listview.)



  • Of course. You cant have both. Either you set a fixed size on a ListView by setting the height property or you have a fixed with container that adapts to the height. You have to choose. QListView worked the same way. You can try to hack it by setting the Listview height to it's contentHeight but then what is the point of having it flickable?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.