首页 > 解决方案 > 如何在 QML 中显示二维 qvariantlist

问题描述

我有一个二维 qvariantlist,我想在 QML 中显示。我一直在尝试使用 Listview,但它只显示您指定的尺寸。例如数组 [0] 数组1 ...

以下代码仅显示第一个维度...:

        Rectangle {
        id: rectangle
        height: 300
        anchors.top: userFields.bottom
        width: parent.width
        ListView {
                id: listView
                anchors.centerIn: parent
                width: 180
                height: 200

                model: RdaDevicePropertyAcess.rdaDataAcquired[userFields.devicePropertyText + '#' + userFields.fieldText]

                delegate: Row {
                    Rectangle {
                        id: first
                        width: listView.width / 3
                        height: 30

                        Text {
                            anchors.centerIn: parent
                            text: modelData[0]
                            font.pointSize: 20
                        }
                    }

                }
            }
    }

我正在看这篇文章,但我没有为我工作。我想拥有相同的内容,但将其显示到 qml 对象中。

我也一直在尝试使用 createObject()javascript 函数,但它对我也不起作用。

有人有什么建议吗?

标签: qtlistviewqmlqvariant

解决方案


我回复自己。最后我用下面的 QML 代码解决了这个问题。我认为这将帮助很多人节省时间。

        Grid {
        id: rectangle
        height: 1000
        columns: _model.myQvariantList.length
        anchors.top: userFields.bottom
        anchors.left: parent.left
        anchors.right: parent.right
        width: 1000
        Repeater {
            model: _model.myQvariantList[0].length
            Repeater {
                model: _model.myQvariantList.length
                id: repeater1
                property int outerIndex: index
                Rectangle {
                    width: 20; height: 20
                    Text
                    {
                        anchors.centerIn: parent
                        text: _model.myQvariantList[index][repeater1.outerIndex]
                        font.pointSize: 10
                    }
                }
            }
        }
    }

推荐阅读