【问题标题】:QML listview OverscrollsQML listview Overscrolls
【发布时间】:2014-02-03 19:53:37
【问题描述】:

我有一个水平列表视图,如图

现在当我滚动它时,列表视图会被过度滚动,如下图所示

我真正需要的是即使拖得更多,最后一个元素应该留在最后,如下图

我该怎么做。

编辑

列表视图源

ListView{

        id: list
        width: 500
        height: 100
        clip: true
        //anchors.bottom: parent.bottom
        //anchors.bottomMargin: 10
        snapMode: ListView.SnapToItem
        anchors.centerIn: parent
        highlightRangeMode: ListView.StrictlyEnforceRange
        highlightFollowsCurrentItem: true
        highlight: Rectangle { color: "#00000000" ;border.color: "red" ; radius: 5 }
        anchors.horizontalCenter: parent.horizontalCenter
        orientation: ListView.Horizontal
        model: ListModel{
            id: listModel
            ListElement{ name: "File"}
            ListElement{ name: "Edit"}
            ListElement{ name: "Build"}
            ListElement{ name: "Debug"}
            ListElement{ name: "Analyze"}
            ListElement{ name: "Tools"}
            ListElement{ name: "Window"}
            ListElement{ name: "Help"}
        }

        delegate: Button{
            borderColor: buttonBorderColor;buttonColor: buttonFillColor
            width: 100;height: 100 ;labelSize: 18
            label: model.name
            onButtonClick: {
                list.currentIndex = model.index;
                console.log("ListView Button clicked" + model.index)
            }
        }
    }

【问题讨论】:

  • 可以提供demo应用吗?
  • 我已经更新了我的问题
  • 您确定您的按钮是来自 QtQuick.Controls 的按钮吗?最后一个没有 label 和 labelSize 属性.....
  • 它不在 QtQuick.Controls 中,它是一个自定义按钮。但我认为“按钮”并不是这种行为背后的原因。
  • 我面临着完全相同的问题。你找到解决办法了吗?

标签: qt listview qml


【解决方案1】:

您需要通过设置boundsBehavior 属性来告诉ListView 在对象边界处停止:

boundsBehavior: Flickable.StopAtBounds

默认情况下,继承 Flickable 的对象会越界并向后移动。

请参阅 Qt 网站上的boundsBehavior property description

【讨论】:

  • 这篇文章被自动标记为低质量,因为它太短/只有代码。您介意通过添加一些文本来解释它如何解决问题来扩展它吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-06-02
  • 2012-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-08
  • 1970-01-01
相关资源
最近更新 更多