首页 > 解决方案 > 将 QML 小部件绑定到列表模型,但让某些小部件仅绑定到特定索引?

问题描述

我正在编写一个与监控服务器对话的 QML GUI。在一种情况下,有 3 个分组的远程系统,一个是主系统,另外两个是从属系统。我有每一个的完整状态,但需要显示主系统的更多细节。

例如,我收到一条更新消息,其中包含:

{
    systems: {
        1: {
            type: Debian,
            name: system1,
            status: OK,
            detailedStatus1: 123,
            detailedStatus2: xyz
        },
        2: {
            type: Ubuntu,
            name: system2,
            status: OK,
            detailedStatus1: 456,
            detailedStatus2: abc
        },
        3: {
            type: Windows,
            name: system3,
            status: OK,
            detailedStatus1: 789,
            detailedStatus2: def
        }
    },
    currentMaster: (1 or 2 or 3)
}

...我想显示所有 3 个系统的类型、名称和状态,但只显示 currentMaster 系统的详细状态 1 和详细状态 2。

我的 QML 模型应该是什么样的?我是否应该有一个我的 detailStatus 小部件绑定到的“masterModel ListModel”,以及一个用于类型/名称/状态的“allsystems ListModel”,并在每次 currentMaster 更改时更新 masterModel?或者有没有办法从单个 "allsystems ListModel" 做到这一点,使用 currentMaster 知道要绑定什么?我应该完全做其他事情吗?

标签: qtqmlqtquick2qabstractlistmodel

解决方案


推荐阅读