qt - 如何在 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 函数,但它对我也不起作用。
有人有什么建议吗?
解决方案
我回复自己。最后我用下面的 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
}
}
}
}
}
推荐阅读
- angular - ExpressionChangedAfterItHasBeenCheckedError 与共享服务
- sql - 搜索字符串并有条件地忽略连字符
- r - 优化在 R 中的地图上绘制市政/区域数据的速度
- bdd - squish 有没有办法在同一个 BDD 步骤中使用复数和单数?
- python - python bigquery get external table meta data
- matrix - 并行求解线性方程组
- android - 找不到用户 0 的提供者;期望为此权限找到一个有效的 ContentProvider
- angular - angular6:我希望我继承的组件具有父组件的一些属性
- javascript - How {}.hasOwnProperty() works?
- bash - Set environment variables in bash file calling a Matlab script