当前位置: 首页 > wzjs >正文

网站网页优化技巧近日网站收录查询

网站网页优化技巧,近日网站收录查询,建网站内容,做网站需要哪些技术人才一、概念 在QML中,Delegate是一种非常重要的组件,特别是在使用ListView、GridView、PathView等视图组件时。Delegate用于定义每个列表或网格中的项目是如何展示的。通过自定义Delegate,你可以控制每个项目的外观和行为。 Delegate通常是一个…

、概念

QML中,Delegate是一种非常重要的组件,特别是在使用ListViewGridViewPathView等视图组件时。Delegate用于定义每个列表或网格中的项目是如何展示的。通过自定义Delegate,你可以控制每个项目的外观和行为。

Delegate通常是一个自定义的ItemComponent,它定义了如何在列表或网格中显示每个项目。例如,你可以在Delegate中定义文本标签、图片、按钮等。

、常用委托控件

常用委托控件:ItemDelegate、CheckDelegate、RadioDelegate、SwitchDelegate和SwipeDelegate。

1.‌ItemDelegate

属性/信号/方法类型说明示例
‌highlighted‌bool当前项高亮状态,常用于列表选中项highlighted: ListView.isCurrentItem
‌text‌string显示的主文本内容text: model.name
‌icon‌var左侧图标资源(QtQuick.Icon类型)icon.source: "icon.png"
‌spacing‌real图标与文本间距(像素)spacing: 10
‌padding‌real内容区域内边距padding: 12
‌onClicked‌signal点击时触发onClicked: console.log(index)
‌background‌Component自定义背景组件background: Rectangle{color:"red"}

代码示例:

    //ItemDelegateListView {id: listViewItemx: 0; y: 0width: 300height: 300model: ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]delegate: ItemDelegate {text: modelDatawidth: listViewItem.widthicon.source:"qrc:/image/user.png"icon.color: "transparent"//icon.name: "edit-cut"display: AbstractButton.TextBesideIconhighlighted: ListView.isCurrentItemonClicked: {listViewItem.currentIndex = index;console.log("clicked:", modelData)}}}

运行结果:

2.CheckDelegate

属性/信号/方法类型说明示例
‌checkState‌enum三态状态(Checked/Unchecked/PartiallyChecked)checkState: Qt.Checked
‌tristate‌bool是否启用三态模式tristate: true
‌checked‌bool当前选中状态checked: model.selected
‌onToggled‌signal状态变化时触发onToggled: model.checked=checked
‌indicator‌Component自定义复选框样式indicator: Rectangle{...}
‌nextCheckState‌method控制点击时的状态切换逻辑function nextCheckState(){...}

代码示例:

    //CheckDelegateproperty var selectedItems: []ListView {id: listViewCheckx: 320; y: 0width: 300height: 300model: ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]delegate: CheckDelegate {text: modelDatawidth: listViewCheck.widthonCheckedChanged: {if (checked) {selectedItems.push(modelData)} else {selectedItems = selectedItems.filter(item => item !== modelData)}}}}Button {text: "Selected Items"anchors.bottom: listViewCheck.bottomanchors.horizontalCenter: listViewCheck.horizontalCenteronClicked: {console.log("Selected items:", selectedItems)}}

运行结果:

3.RadioDelegate

属性/信号/方法类型说明示例
‌autoExclusive‌bool同组单选按钮自动互斥autoExclusive: true
‌checked‌bool当前选中状态checked: model.isSelected
‌onClicked‌signal点击时触发onClicked: group.update(index)
‌indicator‌Component自定义单选按钮样式indicator: Circle{...}
‌text‌string显示文本标签text: model.option

代码示例:

//RadioDelegateproperty string selectedItem: "Item 1"  // 默认值需与初始checked项匹配ListView {id: listViewRadiox: 640; y: 0width: 300height: 300model: ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]delegate: RadioDelegate {text: modelDatawidth: listViewRadio.widthchecked: selectedItem === modelDataonCheckedChanged: {if (checked) {selectedItem = modelData}}}}Button {text: "Selected Item"anchors.bottom: listViewRadio.bottomanchors.horizontalCenter: listViewRadio.horizontalCenteronClicked: console.log("Selected Item:", selectedItem)}

运行结果:

4.SwitchDelegate

属性/信号/方法类型说明示例
‌position‌real滑块位置(0.0-1.0)position: 0.7
‌checked‌bool当前开关状态checked: model.active
‌onToggled‌signal状态变化时触发onToggled: settings.save()
‌indicator‌Component自定义滑块组件indicator: Slider{...}
‌visualPosition‌real动画过渡中的可视位置visualPosition: 0.5

代码示例:

    //SwitchDelegateListView {id: listViewSwitchx: 0; y: 320width: 300height: 300model: ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]delegate: SwitchDelegate {text: modelDatawidth: listViewSwitch.width}}

运行结果:

 5.SwipeDelegate

属性/信号/方法类型说明示例
‌swipe.left‌Component左滑时显示的组件swipe.left: Rectangle{...}
‌swipe.right‌Component右滑时显示的组件swipe.right: Image{...}
onCompletedsignal完成滑动操作时触发onCompleted: list.remove(index)
‌swipe.position‌real当前滑动进度(-1.0到1.0)swipe.position: 0.3
‌behind‌Component滑动后显示的背景组件behind: DeleteButton{...}

代码示例:

//SwipeDelegateListModel {id: listModelListElement { name: "Item 1" }ListElement { name: "Item 2" }ListElement { name: "Item 3" }ListElement { name: "Item 4" }ListElement { name: "Item 5" }}// 列表视图ListView {x: 320; y: 320width: 300height: 300model: listModeldelegate: SwipeDelegate {width: parent.widthheight: 60text: nameswipe.left: Rectangle {width: parent.widthheight: parent.heightcolor: "#ff4444"Label {anchors.centerIn: parenttext: "删除"color: "white"font.bold: true}// 点击删除按钮时移除项目MouseArea {anchors.fill: parentonClicked: listModel.remove(index)}}// 滑动完成时自动恢复位置//swipe.onCompleted: swipe.close()}// 滚动条ScrollIndicator.vertical: ScrollIndicator {}}

运行结果:

关键特性说明:

  1. 所有Delegate均继承自AbstractButton,支持点击/按压等基础交互
  2. 自定义样式推荐通过覆盖backgroundcontentItem实现
  3. SwipeDelegate需配合ListView使用才能获得完整手势支持

完整代码

代码:

import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls 2.6Window {visible: truewidth: 960height: 640title: qsTr("Hello World")//ItemDelegateListView {id: listViewItemx: 0; y: 0width: 300height: 300model: ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]delegate: ItemDelegate {text: modelDatawidth: listViewItem.widthicon.source:"qrc:/image/user.png"icon.color: "transparent"//icon.name: "edit-cut"display: AbstractButton.TextBesideIconhighlighted: ListView.isCurrentItemonClicked: {listViewItem.currentIndex = index;console.log("clicked:", modelData)}}}//CheckDelegateproperty var selectedItems: []ListView {id: listViewCheckx: 320; y: 0width: 300height: 300model: ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]delegate: CheckDelegate {text: modelDatawidth: listViewCheck.widthonCheckedChanged: {if (checked) {selectedItems.push(modelData)} else {selectedItems = selectedItems.filter(item => item !== modelData)}}}}Button {text: "Selected Items"anchors.bottom: listViewCheck.bottomanchors.horizontalCenter: listViewCheck.horizontalCenteronClicked: {console.log("Selected items:", selectedItems)}}//RadioDelegateproperty string selectedItem: "Item 1"  // 默认值需与初始checked项匹配ListView {id: listViewRadiox: 640; y: 0width: 300height: 300model: ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]delegate: RadioDelegate {text: modelDatawidth: listViewRadio.widthchecked: selectedItem === modelDataonCheckedChanged: {if (checked) {selectedItem = modelData}}}}Button {text: "Selected Item"anchors.bottom: listViewRadio.bottomanchors.horizontalCenter: listViewRadio.horizontalCenteronClicked: console.log("Selected Item:", selectedItem)}//SwitchDelegateListView {id: listViewSwitchx: 0; y: 320width: 300height: 300model: ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]delegate: SwitchDelegate {text: modelDatawidth: listViewSwitch.width}}//SwipeDelegateListModel {id: listModelListElement { name: "Item 1" }ListElement { name: "Item 2" }ListElement { name: "Item 3" }ListElement { name: "Item 4" }ListElement { name: "Item 5" }}// 列表视图ListView {x: 320; y: 320width: 300height: 300model: listModeldelegate: SwipeDelegate {width: parent.widthheight: 60text: nameswipe.left: Rectangle {width: parent.widthheight: parent.heightcolor: "#ff4444"Label {anchors.centerIn: parenttext: "删除"color: "white"font.bold: true}// 点击删除按钮时移除项目MouseArea {anchors.fill: parentonClicked: listModel.remove(index)}}// 滑动完成时自动恢复位置//swipe.onCompleted: swipe.close()}// 滚动条ScrollIndicator.vertical: ScrollIndicator {}}
}

运行结果:

http://www.dtcms.com/wzjs/90816.html

相关文章:

  • 虚拟现实技术seo网络推广培训班
  • 长春网站建设及推广友情链接样式
  • 怎样做网站seo优化网站推广怎么弄
  • 网站开发项目报价单竞价推广托管公司介绍
  • javaee做网站建设西安网站定制开发
  • 国外网站 服务器关键词推广
  • 可以做翻译任务的网站在线域名ip查询
  • 北京企业网站备案需要多久百度帐号登录
  • 电视台网站模版浙江关键词优化
  • 怎么在网站后台做标题的超链接社群营销平台有哪些
  • 神华集团 两学一做 网站企业网络营销方案设计
  • 怎样做约票的网站意思免费推广网站视频
  • 专业网站推广引流国家市场监管总局官网
  • 网站开发用的工具长沙seo培训班
  • 网站网页设计方案关键词优化怎么写
  • 招聘网站如何做运营站长之家seo
  • 网站创建风格品牌推广的意义
  • 新网站制作市场seo产品优化免费软件
  • 网站定制电话最佳搜索引擎
  • 做公司英文网站东莞seo网络公司
  • 网站3d展示怎么做的专门制作小程序的公司
  • 网站建设广告素材推广策略有哪些方法
  • php网站api接口写法百度收录排名查询
  • 什么网站排名做的最好杭州云优化信息技术有限公司
  • 值得浏览的国外网站简单制作html静态网页
  • 接单做效果图网站广告策划书
  • 豆各庄做网站的公司2345网址中国最好
  • 怎么自己做网站备案seo优化关键词是什么意思
  • 北京网站建设怎么样长沙靠谱关键词优化公司电话
  • 网站做造价如何推广软件