QML ListView在其边界之外绘制ObjectModel [英] QML ListView draws ObjectModel outside of its bounds

查看:407
本文介绍了QML ListView在其边界之外绘制ObjectModel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图从WPF/XAML进入QT/QML.

I'm trying to get into QT/QML coming from WPF/XAML.

在测试GUI中,我使用ListView在单击按钮时显示不同的模型. 到目前为止,此方法还可以正常工作,当我单击相应的按钮时,视图将继续显示每个模型. 但是它仍然将所有其他模型绘制在其自身的边界之外,从而将周围的元素与它们重叠. 我可以关闭这种行为吗?

In a test GUI, I'm using a ListView to display different Models on click of a button. This works alright so far, the view keeps showing each model when I click the corresponding button. But it still draws all the other models outside of its own bounds, overlapping surrounding elements with them. Can I turn this behaviour off?

这是我的ListView:

This is my 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:

And this is the 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
    }
}

由于我已经习惯了XAML,因此我仍然在QML的布局和锚定概念上苦苦挣扎.因此,如果我犯了一个明显的错误,请原谅.

I'm still struggling a bit with the layout and anchoring concepts of QML, since I'm used to XAML. So please excuse if I'm making an obvious mistake.

推荐答案

似乎Item的"clip"属性将帮助您: Item.clip

Seems that "clip" property of Item will help you: Item.clip

这篇关于QML ListView在其边界之外绘制ObjectModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆