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

QML Item

在QML中所有的可视项目都继承自Item,虽然Item本身没有可视化的外观,但它定义了可视化项目的所有属性。

Item可以作为容器使用:

Item{Rectangle{id:retc}Rectangle{id:retc1}Rectangle{id:retc2}Rectangle{id:retc3}}

item拥有children属性和resources

  • children可以获取可见的孩子列表
  • resources 包含了不可见的资源

children的使用:

如果只有一个元素的话,可以不用使用children

  • 使用children[   ]
  • 有多个使用,隔开
Item{children: [Text {id: t0;text: "text0"},Text {id: t1;text: "text1"},Text {id: t2;text: "text2"},Text {id: t3;text: "text3"},Text {id: t4;text: "text4"}]Component.onCompleted: {console.log("index 0的内容为:",children[0].text)console.log("index 1的内容为:",children[1].text)console.log("index 2的内容为:",children[2].text)console.log("index 3的内容为:",children[3].text)console.log("index 4的内容为:",children[4].text)}}

 resources 的使用:

resources: [Timer{}]

Item中还有一个data默认属性,允许在项目中将可见和不可见的资源自由混合,由于data是默认 属性,所以可以省略data标签。

Item{Text {id: t0;text: "text0"}Text {id: t1;text: "text1"}Text {id: t2;text: "text2"}Text {id: t3;text: "text3"}Text {id: t4;text: "text4"}Timer{}Component.onCompleted: {console.log("index 0的内容为:",children[0].text)console.log("index 1的内容为:",children[1].text)console.log("index 2的内容为:",children[2].text)console.log("index 3的内容为:",children[3].text)console.log("index 4的内容为:",children[4].text)}}

 opacity(透明度)

  • 0.0 全透明    
  • 1.0 完全不透明
 Item{Rectangle{width: 100height: 100color: "red"opacity: 0}Rectangle{x:110y:0width: 100height: 100color: "red"opacity: 0.2}Rectangle{x:220y:0width: 100height: 100color: "red"opacity: 0.5}Rectangle{x:330y:0width: 100height: 100color: "red"opacity: 1.0}
}

 堆叠顺序

Item拥有一个z属性,可以设置堆叠顺序,默认的堆叠顺序为0,z数值大的优先绘制。

如果都没设置的话,根据项目顺序(由上到下)绘制。

Item{Rectangle{width: 100height: 100color: "red"}Rectangle{width: 100height: 100color: "blue"}
}

Item{    Rectangle{z:1width: 100height: 100color: "red"}Rectangle{width: 100height: 100color: "blue"}
}

 定位子项目和坐标映射

  • Item中 提供childAt(real x,real y)函数来返回点(x,y)处的子项目,没有的话返回null。
  • mapFromItem(Item item,real x,real y):项目坐标系中的点 (x, y)映射到此项的坐标系,并返回与映射坐标匹配的点
  • mapToItem(Item item,real x,real y) :将该项目坐标系中的点(x、y)映射到项目的坐标系,并返回与映射坐标匹配的点。

transitions过渡)

使用transitions来存储项目的过渡列表

Item{id:item2transitions :[Transition {},Transition {},Transition {}]}

states(状态)

使用states来保存该项的可能状态列表

Rectangle {id: rootwidth: 100; height: 100states: [State {name: "red_color"//状态1PropertyChanges { target: root; color: "red" }},State {name: "blue_color"//状态2PropertyChanges { target: root; color: "blue" }}]
}

常见的一些属性:

rotation旋转
smooth平滑处理(默认true)
scale缩放
parent父类
opacity透明
focus焦点
clip剪辑(默认false)
antialiasing抗齿状
layer.enabled是否分层

layer.enabled 是否分层

 非分层不透明度:

Item{opacity: 0.5width: 250height: 250Rectangle{id:rect1;width:100;height: 100;color:"red" ;border.width:1}Rectangle{id:rect2;width:100;height: 100;color: "blue";x:50;y:50;border.width:1}}

分层不透明度:

Item{opacity: 0.5layer.enabled: truewidth: 250height: 250Rectangle{id:rect1;width:100;height: 100;color:"red" ;border.width:1}Rectangle{id:rect2;width:100;height: 100;color: "blue";x:50;y:50;border.width:1}}

http://www.lryc.cn/news/23088.html

相关文章:

  • 使用xca工具生成自签证书
  • Unity IOS 通过命令行导出IPA
  • 「架构」全链路异步模式
  • CleanMyMac4.20最新版新增功能及电脑清理垃圾使用教程
  • Vue2的tsx开发入门完全指南
  • GLSL shader学习系列1-Hello World
  • Codeforces Round #851 (Div. 2)(A~D)
  • 内存保护_1:Tricore芯片MPU模块介绍
  • Vue3 -- PDF展示、添加签名(带笔锋)、导出
  • 行测-判断推理-图形推理-样式规律-属性规律-曲直性
  • idea集成Alibaba Cloud Toolkit插件
  • Win11 文件夹打开慢或卡顿解决方案
  • 【PostgreSQL的idle in transaction连接状态】
  • cityengine自定义纹理库资源
  • taobao.top.secret.bill.detail( 服务商的商家解密账单详情查询 )
  • 2023软件测试金三银四常见的软件测试面试题-【抓包和网络协议篇】
  • vue脚手架多页自动化生成实践
  • 【SQL语句优化】
  • 阿里P8:做测试10年我的一些经验分享,希望你们少走弯路
  • 栈在括号匹配中的应用(栈/链栈 纯C实现)
  • C语言Switch语句用法
  • Curl编码请求参数,API接口请求示例参数
  • 【C/C++】类型限定符extern、const、Volatile、register
  • day54【代码随想录】二刷数组
  • 哪个品牌蓝牙耳机性价比高?性价比高的平价蓝牙耳机推荐
  • 揭秘关于TFRcord的五脏六腑
  • 【Shell学习笔记】3.Shell 传递参数及数组
  • 【终结Bug】ModuleNotFoundError: No module named ‘cv2’
  • SQL Server2008详细安装步骤(保姆式教程)
  • Linux常用操作