【问题标题】:Horizontal listview display over its boundary水平列表视图显示在其边界上
【发布时间】:2016-08-12 08:29:24
【问题描述】:

我创建了一个矩形来包裹水平列表视图,但它显示在其边界之上。问题如下图: 在此图像中,列表视图显示当前显示项目的前面和下面的项目。当时如何只显示当前项目,当用户滑动列表视图时,项目更改一项?

我的源代码在这里:

ApplicationWindow {
visible: true
width: 900
height: 480
title: qsTr("Hello World")

Rectangle{
    id: bound
    anchors.fill: parent
    color: "blue"
}

Rectangle{
    id: listview
    width: 300
    height: 300
    anchors.centerIn: parent
    color: "red"
    ListView{
        id:lst
        width: 250
        height: 250
        orientation: ListView.Horizontal
        snapMode: ListView.SnapOneItem
        //preferredHighlightBegin: 0
        //preferredHighlightEnd: 200
        highlightRangeMode: ListView.StrictlyEnforceRange
        boundsBehavior: Flickable.StopAtBounds
        highlightFollowsCurrentItem: true
        keyNavigationWraps: true
        interactive: true
        model: 10
        delegate: Rectangle{
            id: dele
            width: 250
            height: 250
            anchors.centerIn: listview
            color: Qt.rgba(Math.random(),Math.random(),Math.random(),1)
        }
    }
}

}

【问题讨论】:

    标签: qt listview delegates qml qtquick2


    【解决方案1】:

    ListView 默认不clip。您可以在需要时设置clip: true。更多详情:http://doc.qt.io/qt-5/qtquick-performance.html#clipping

    【讨论】:

    • 非常感谢。我尝试了一整天,但在您的帮助下找不到解决方案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-01
    • 1970-01-01
    • 2019-02-27
    • 2020-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多