【问题标题】:QML ListView draws ObjectModel outside of its boundsQML ListView 在其边界之外绘制 ObjectModel
【发布时间】:2015-01-15 08:48:40
【问题描述】:

我正在尝试使用来自 WPF/XAML 的 QT/QML。

在测试 GUI 中,我使用 ListView 在单击按钮时显示不同的模型。 到目前为止一切正常,当我单击相应的按钮时,视图会继续显示每个模型。 但它仍然会在自己的范围之外绘制所有其他模型,并与它们重叠周围的元素。 我可以关闭此行为吗?

这是我的列表视图:

ListView
{
    id: list_view

    anchors.fill:                   parent
    model:                          main_view_model
    snapMode:                       ListView.SnapOneItem
    boundsBehavior:                 Flickable.StopAtBounds
    highlightFollowsCurrentItem:    true
    highlightMoveDuration:          75
    highlightRangeMode:             ListView.StrictlyEnforceRange
    currentIndex:                   view_index
}

这是 ObjectModel:

ObjectModel
{
    id: main_view_model

    // ListView index 0
    TestView1
    {
        anchors.centerIn: parent.center
        width: list_view.width
        height: list_view.height
    }

    // ListView index 1
    TestView2
    {
        anchors.centerIn: parent.center
        width: list_view.width
        height: list_view.height
    }

    // ListView index 2
    TestView3
    {
        anchors.centerIn: parent.center
        width: list_view.width
        height: list_view.height
    }

    // ListView index 3
    TestView4
    {
        anchors.centerIn: parent.center
        width: list_view.width
        height: list_view.height
    }
}

我仍然对 QML 的布局和锚定概念有些苦恼,因为我已经习惯了 XAML。所以如果我犯了一个明显的错误,请原谅。

【问题讨论】:

  • 就我个人而言,我无法为您提供帮助,因为您的代码无法运行。如果您可以通过使用 Rectangles 而不是 TestView1、TestView2 等来缩小问题范围,并声明缺少的属性(如 view_index),您可能会获得更多帮助。

标签: listview qml


【解决方案1】:

似乎 Item 的“剪辑”属性会帮助您: Item.clip

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-15
    • 2018-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-16
    • 1970-01-01
    相关资源
    最近更新 更多