Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt 带listview的可滚动页面_Qt_Qml_Qt5_Qtquickcontrols2 - Fatal编程技术网

Qt 带listview的可滚动页面

Qt 带listview的可滚动页面,qt,qml,qt5,qtquickcontrols2,Qt,Qml,Qt5,Qtquickcontrols2,我有一个名为page2.qml的文件,如下所示 Page { id: page Rectangle { id: container anchors.fill: parent width: parent.width * 0.8 Rectangle { id: title anchors.top: pare

我有一个名为page2.qml的文件,如下所示

Page {
        id: page

        Rectangle {
            id: container
            anchors.fill: parent
            width: parent.width * 0.8

            Rectangle {
                id: title
                anchors.top: parent.top
                width: parent.width
                height: 50
                color: "salmon"
            }

            ListView {
                id: listView
                currentIndex: -1
                anchors.top: title.bottom
                anchors.bottom: parent.bottom


                delegate: Rectangle {
                    height: 20
                    width: 100
                    border.color: "red"
                    color: "pink"
                    Text {
                        text: model.index
                    }
                }

                model: 100
            }
        }
    }
结果如下图所示:


由于listview包含100项,如何使整个页面可滚动?我可以只使listview可滚动,但不能使整个页面可滚动。

如果您不需要
listview
可滚动,但整个容器需要滚动,您可以使用
转发器
将其放在
列中,并用
Flickable
包装:

Flickable {
    id: container
    contentHeight: column.implicitHeight
    contentWidth: width
    width: parent.width * 0.8
    height: parent.height

    Column {
        id: column
        width: parent.width

        Rectangle {
            id: title
            width: parent.width
            height: 50
            color: "salmon"
        }

        Repeater {
            id: listView
            model: 100

            delegate: Rectangle {
                height: 20
                width: 100
                border.color: "red"
                color: "pink"
                Text {
                    text: model.index
                }
            }
        }
    }
}

将您的
容器
设置为@PraveenKumar我将容器包装在一个
flickable
中,然后设置
contentHeight:title.height+listView.contentHeight
,效果非常好,非常感谢。@PraveenKumar请将您的评论作为答案发布,这样我就可以接受它了。下面的示例为您提供了一个更好的答案:)。如果它真的对你有帮助,那就投票吧。