码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • qml里使用组件的案例


    1. import QtQuick 2.12
    2. import QtQuick.Window 2.12
    3. import QtQuick.Controls 2.12
    4. import QtQuick 2.7
    5. import QtQuick.Layouts 1.3
    6. Window {
    7. visible: true
    8. width: 640
    9. height: 480
    10. title: qsTr("Hello World")
    11. Component{
    12. id:com01
    13. Rectangle{
    14. id:rec01
    15. width: 15
    16. height:75
    17. color: "red"
    18. property int age: 399
    19. signal deleteThis()
    20. Button{
    21. id:btn02
    22. text: "1"
    23. property int age: 77
    24. width: 50
    25. y:5
    26. onClicked: {
    27. rec01.deleteThis()
    28. }
    29. Button{
    30. id:btn01 //刻意和全局某按钮id一样,并没有报冲突 说明component里面是一个黑盒子
    31. x:150
    32. //property int age: 77
    33. width: 50
    34. height: 50
    35. background: {
    36. color:"red"
    37. }
    38. text: age //这个age优先从本对象找 如果没找到就从根对象里面找
    39. onClicked: {
    40. console.log("99")
    41. btn02.dada(); //不能简写dada(),明确指定调用的是btn02这个对象的dada方法
    42. xxx() //xxx函数优先从本对象找 如果没找到就从根对象里面找
    43. }
    44. function jia02(a,b){
    45. //打印结果 qml: componentt jia02 :154 : 1 : 961 : 0
    46. console.log("componentt jia02 :"+(a+b)+ " : "+btn02.text+" : "+text+" : "+y)
    47. }
    48. function xxx(){
    49. console.log("xxx ...")
    50. }
    51. }
    52. function dada(){
    53. console.log("da da ...")
    54. }
    55. }
    56. function jia(a,b){
    57. console.log(a+b)
    58. btn01.jia02(88,66)
    59. }
    60. }
    61. }
    62. Loader{
    63. id:myloader01
    64. sourceComponent:com01
    65. function onDisDeleteThis() {
    66. myloader01.sourceComponent = undefined
    67. }
    68. onLoaded: {
    69. item.age = 325
    70. myloader01.item.deleteThis.connect(myloader01.onDisDeleteThis)
    71. }
    72. }
    73. Loader{
    74. x:250
    75. id:myloader02
    76. sourceComponent:com01
    77. function onDisDeleteThis() {
    78. myloader02.sourceComponent = undefined
    79. }
    80. onLoaded: {
    81. item.age = 311
    82. myloader02.item.deleteThis.connect(myloader02.onDisDeleteThis)
    83. }
    84. }
    85. Button{
    86. id:btn01
    87. x:100
    88. y:100
    89. text: "clickbtn"
    90. onClicked: {
    91. myloader01.item.color="orange"
    92. myloader01.item.age=169
    93. myloader02.item.color="green"
    94. myloader02.item.age=961
    95. myloader02.item.jia(78,25)
    96. }
    97. }
    98. }

    FR:徐海涛(hunkxu) 

  • 相关阅读:
    构建器模式-C++实现
    【jq】如何优雅在shell脚本处理json?
    安装、配置 Java JDK 和 JRE,并卸载自带 OpenJDK
    【目标检测】SPP-Net论文理解(超详细版本)
    题348.差分约束-acwing-Q362--区间
    数据结构—快速排序(续)
    超图嵌入论文阅读2:超图神经网络
    Nacos为什么对于临时实例采用心跳检测,非临时实例采用主动询问?Nacos同时作为配置中心和注册中心有什么坏处?为什么Nacos可以抗住那么高的注册?
    构建LangChain应用程序的示例代码:14、使用LangChain、GPT和Activeloop的Deep Lake来处理代码库
    redis命令记录
  • 原文地址:https://blog.csdn.net/qq_15267341/article/details/139740291
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号