是否有可能从内部QML中继器(它们是嵌套的)到达外部QML中继器的索引的? [英] Is there any possibility to reach the index of an outer QML Repeater from the inner one (they are nested)?

查看:161
本文介绍了是否有可能从内部QML中继器(它们是嵌套的)到达外部QML中继器的索引的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在QML应用程序中动态构建相同类型项目的矩阵,并使其保持动态,以便您可以随时更改c ++文件中的行数和列数.这一直很好,但是现在,要单独访问它们,我想给它们提供动态名称.因此,我嵌套了两个转发器,并尝试如下设置objectName:

I am trying to dynamically build a matrix of the same type of items in my QML application and keep it dynamic, so that you can change the number of rows and columns in a c++ file anytime. This has been working well, but now, to access them individually, I want to give them dynamic names. Therefore I nested two repeaters and tried to set the objectName as in the following:

    Repeater{
        id: rows
        model: Matrix1.row //number of rows in Matrix1-Object

        Repeater{
            id: columns
            model: Matrix1.column //number of columns in Matrix1-Object

            RepeatedItem{
                objectName: (index) +"."+ (rows.index) //matrix elements are 
                supposed to be numbered x.y because of the nested repeaters, e.g. 
                0.0 for the first element
            }
        }
    }

不幸的是,我似乎无法访问外部索引. 显示第一个值,第二个值由我的GUI的TextArea中的字符串 undefined 表示. 如果我将一个新属性添加到外部Repeater并将其设置为与index相同的值,它将被设置一次并为每个重复的行保留第一个值(0).

Unfortunately I seem to have no access to the outer index. The first value is shown, the second value is represented by the String undefined in the TextArea of my GUI. In case I add a new property to the outer Repeater and set it the same value as index, it will be set once and keep the first value (0) for each repeated row.

是否不可能以某种方式动态达到此外部索引值? 还是有人知道更好的方法来动态创建可单独访问的QML项目的二维数组?

Is it impossible to dynamically reach this outer index value somehow? Or does anyone know a better way to dynamically create two-dimensional arrays of items in QML which are individually accessable?

推荐答案

index属性是上下文属性.您可以将其存储到普通属性,因此可以从另一个上下文访问它:

The index property is a context property. You can store it to an ordinary property, so you can access it from another context:

Repeater {
    id: rows
    // ...
    Repeater {
        id: columns
        property int outerIndex: index
        // ...
        Text {
            text: index + "." + columns.outerIndex
        }
    }
}

这篇关于是否有可能从内部QML中继器(它们是嵌套的)到达外部QML中继器的索引的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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