QML ScrollView with ColumnLayout

后端 未结 2 388
你的背包
你的背包 2021-01-12 02:30

I am trying to create a scroll view around a ColumnLayout, unfortunately my current code doesn\'t work. I know about ListView, but in my case I need to create scrollable Lay

2条回答
  •  自闭症患者
    2021-01-12 02:45

    I would go with a plain column and access the desired width property directly by id. As I understand these container elements are measuring their size depending on their content, that might be the reason why setting the ColumnLayouts width has no effect.

    This works for me:

    ScrollView 
    {
        anchors.fill: parent
    
        Column {
    
            Repeater {
                model: 4;
                delegate: Item {
                    width: root.width;
                    height: image.sourceSize.height;
    
                    Image {
                        id: image;
                        anchors.centerIn: parent;
                        width: parent.width;
                        fillMode: Image.Stretch;
                        source: "img" + (index+1) + ".png"
                    }
                }
            }
        }
    }
    

    In my case root is just the parent's id. Hope this helps!

提交回复
热议问题