有时,链表的数据需要分组。例如使用首字母来划分联系人,或者分类音乐。使用链表视图可以把平面列表按类别划分。
为了使用分组,section.property与section.criteria必须设置。section.property定义了哪些属性用于内容的划分。在这里,最重要的是知道每一组的元素必须连续,否则相同的属性名可能出现在几个不同的地方。
section.criteria能够被设置为ViewSection.FullString或者
ViewSection.FirstCharacter。默认下使用之一个值,能够被用于模型中有清晰的分组,例如音乐专辑。第二个是使用一个属性的首字母来分组,这说明任何属性都可以被使用。通常的例子是用于联系人名单中的姓。
当组被定义好后,每个子项能够使用绑定属性ListView.section,ListView.previousSection与ListView.nextSection来访问。使用这些属性,可以检测组的之一个与最后一个子项。
使用ListView的section.delegate属性可以给组指定 *** 组件。它能够创建段标题,并且可以在任意子项之前插入这个段 *** 。使用绑定属性section可以访问当前段的名称。
下面这个例子使用国际分类展示了分组的一些概念。国籍作为section.property,组 *** 组件(section.delegate)使用每个国家作为标题。在每个组中,spacemen模型中的名字使用spaceManDelegate组件来 *** 显示。
import QtQuick 2.3 import QtQuick.Window 2.2
Window { id: root visible: true width: 480 height: 300 color: "white"
ListView { anchors.fill: parent anchors.margins: 20 clip: true model: spaceMen delegate: spaceManDelegate section.property: "nation" section.delegate: sectionDelegate }
Component { id: spaceManDelegate Item { width: 260 height: 20 Text { anchors.left: parent.left anchors.verticalCenter: parent.verticalCenter anchors.leftMargin: 10 font.pixelSize: 12 text: name } } }
Component { id: sectionDelegate Rectangle { width: 260 height: 20 color: "lightBlue" Text { anchors.left: parent.left anchors.verticalCenter: parent.verticalCenter anchors.leftMargin: 10 font.pixelSize: 12 font.bold: true text: section } } }
ListModel { id: spaceMen ListElement { name: "小赵"; nation: "中国" } ListElement { name: "小钱"; nation: "中国" } ListElement { name: "小孙"; nation: "中国" } ListElement { name: "小李"; nation: "中国" } ListElement { name: "Amy"; nation: "美国" } ListElement { name: "David"; nation: "美国" } ListElement { name: "Kim"; nation: "美国" } ListElement { name: "Helen"; nation: "俄罗斯" } ListElement { name: "Kate"; nation: "俄罗斯" } } }
运行效果如下:
如果同一组下的内容不联系,如下面的代码所示:
ListModel { id: spaceMen ListElement { name: "小赵"; nation: "中国" } ListElement { name: "小钱"; nation: "中国" } ListElement { name: "Amy"; nation: "美国" } ListElement { name: "Kim"; nation: "美国" } ListElement { name: "Helen"; nation: "俄罗斯" } ListElement { name: "Kate"; nation: "俄罗斯" } ListElement { name: "小孙"; nation: "中国" } ListElement { name: "小李"; nation: "中国" } ListElement { name: "David"; nation: "美国" } }
即会出现多个相同的属性名,运行效果如下:
Google已经为Windows、Mac和Linux用户发布了Chrome 99.0.4844.84,以解决一个在外部被利用的高严重性零日漏洞。浏览器供应商在周五发布的安全公告中说:”Google已经得知CVE-2022-1096的一个漏洞存在于外部。” 99.0.4844.84版本已经在稳定的桌...
GitHub今天透露,一名攻击者正在使用偷来的OAuth用户令牌(原本发放给Heroku和Travis-CI),从私人仓库下载数据。自2022年4月12日首次发现这一活动以来,威胁者已经从几十个使用Heroku和Travis-CI维护的OAuth应用程序(包括npm)的受害组织中访问并窃取数据。...
由周四发布的“网络垃圾”(Webspam)报告可知,谷歌搜索在 2021 年过滤的垃圾网站数量、竟是 2020 年的六倍。据悉,作为 Alphabet 旗下子公司,Google 有一套名为 SpamBrian 的人工智能垃圾过滤系统,并且可在超过 99% 情况下实现“不受垃圾所困扰”(spam-fr...
为了迎接今年 5 月首个周四的“世界密码日”的到来,USA Today 觉得很有必要继续提醒大家提升安全意识。首先是尽量为工作、娱乐、网银、网购等各种在线活动配备强密码,且需避免使用同一个密码,以免所有账号被攻击者一锅端。 资料图(来自:Bitwarden) 业内知名开源密码器(US News &...
Hackernews 编译,转载请注明出处: QNAP网络连接存储(NAS)设备的用户报告了eCh0raix勒索软件(也称为QNAPCrypt)对其系统的攻击。 这一特定恶意软件背后的攻击者在圣诞节前一周左右加强了攻击力度,用管理员权限控制设备。 圣诞节前攻击次数增加 BleepingCompute...
Check Point Research 在近期发布的联发科芯片组的 AI 和音频处理组件中发现了一个漏洞,或被别有用心者利用于本地权限提升攻击。这意味着通过精心设计的代码,第三方应用程序可访问它不该接触到 AI 和音频相关信息 —— 理论上甚至可用于窃听。庆幸的是,该漏洞从未被发现有在野外被利用,...