QML ScrollView with ColumnLayout

后端 未结 2 370
你的背包
你的背包 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!

    0 讨论(0)
  • 2021-01-12 03:02

    Same problem on my side. This worked for me :

    ScrollView {
        width: parent.width
        height : parent.height
        contentWidth: column.width    // The important part
        contentHeight: column.height  // Same
        clip : true                   // Prevent drawing column outside the scrollview borders
    
        Column {
            id: column
            width: parent.width
    
            // Your items here
        }
    }
    
    0 讨论(0)
提交回复
热议问题