gpt4 book ai didi

qt - QML:将滚动条附加到ListView

转载 作者:行者123 更新时间:2023-12-03 01:13:18 26 4
gpt4 key购买 nike

我在使用 ListView 时遇到问题。 ListView 太长,部分出现在窗口之外,但我无法附加滚动条。我尝试了很多不同的组合。我认为问题出在高度参数上,但如果删除它,ListView 只显示第一个条目。

Column{
anchors.fill: parent
Row{
id: buttonsRow
Button{
text: "Open dump file"
onClicked: fileDialog.visible = true
}
Button{
text: "Copy raw data to clipboard"
}
}
ListView{
id: listView
anchors.top: buttonsRow.bottom
height: contentHeight
//clip: true
flickableDirection: Flickable.VerticalFlick
boundsBehavior: Flickable.StopAtBounds
interactive: true
model: ListModel{
id: listModel
}
delegate: MDelegate{}
}
}

有什么办法让它可以滚动吗?

最佳答案

在您发布的代码中,我根本没有看到您附加了滚动条。您实际上需要在 ListView 中包含一个 ScrollBar 组件,如下所示:

    ListView { 
id: listView
ScrollBar.vertical: ScrollBar {
active: true
}
}

请参阅“将 ScrollBar 附加到 Flickable”,地址:https://doc.qt.io/qt-5/qml-qtquick-controls2-scrollbar.html

关于qt - QML:将滚动条附加到ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45650226/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com