[英]Turning off the bouncing animation for QML GridView elements
我正在使用 StackView 构建 QtQuick 应用程序。 一切都很顺利,除了一件对我来说很重要的事情。 我正在使用 GridView 通过委托创建一些按钮或表格。 但是,如果用户单击这些代表(我的情况是矩形)并将其拖动到顶部或底部,元素(矩形)就会移动。 当用户释放它时,它会回到原来的位置。 我正在寻找一种解决方案来固定它们。 这是我的片段
ListModel {
id: stepList
ListElement { name: "button1"; src:"/images/stepsTitleActive.png"; }
ListElement { name: "button2"; src:"/images/stepsTitle.png" ; }
}
GridView {
id: stepListGrid
anchors.fill: parent
anchors.leftMargin: 42
anchors.topMargin: 73
model: stepList
cellHeight: 31
cellWidth: 164
delegate: Rectangle { // this is the place where i create buttons
id: rectfor
width: 158
height: 31
color: "transparent"
radius: 20
Text { // t his is the place where i put some texts in the buttons
color: "#4A4A4A"
text: name
font.family: "SF Pro Text"
font.weight: 500
font.pixelSize: 11
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
anchors.topMargin: 9
z: 999
}
Image { // this is the place background for buttons(rectangles)
id: stepListBackground
anchors.fill: parent
source: src
}
}
}
用户可以单击并按住 button1 并可以上下移动整个 gridview 元素。 我想禁用它。 我已经阅读了下面的这份文件,但无法弄明白。
https://doc-snapshots.qt.io/qt6-dev/qml-qtquick-gridview.html#delegate-prop
GridView
是一个Flickable
, Flickable
是为移动使用而设计的。 您需要将属性boundsBehavior
设置为Flickable.StopAtBounds
。 默认值为Flickable.DragAndOvershootBounds
。 查看Flickable文档。
这修复了超调行为,但如果您的 GridView 中有足够的项目,它仍然可以被用户拖动/轻弹。 要停用它,您需要将interactive
设置为false
。 如果这样做,您需要确保您的用户仍然可以滚动 GridView 以到达所有可能不在视图中的项目。 可能您需要用 ScrollView 装饰 Flickable/GridView。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.