码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • QT QML 界面设计教程2——图标(图片)按钮样式


    MyIconButton.xml

    1. import QtQuick 2.4
    2. Rectangle {
    3. id: rec
    4. property alias img_src: icon.source
    5. property alias btn_txt: button.text
    6. property color clr_enter: "#dcdcdc"
    7. property color clr_exit: "#ffffff"
    8. property color clr_click: "#aba9b2"
    9. property color clr_release: "#ffffff"
    10. //自定义点击信号
    11. signal clickedLeft()
    12. signal clickedRight()
    13. signal release()
    14. width: 130
    15. height: 130
    16. radius: 10
    17. Image {
    18. id: icon
    19. width: 100
    20. height:100
    21. source: "qrc:/mycamera.png" //图片资源
    22. fillMode: Image.PreserveAspectFit
    23. clip: true
    24. anchors.top: parent.top
    25. anchors.right: parent.right
    26. anchors.left: parent.left
    27. anchors.margins: 0
    28. }
    29. Text {
    30. id: button
    31. text: qsTr("button")
    32. anchors.top: icon.bottom
    33. anchors.topMargin: 5
    34. anchors.horizontalCenter: icon.horizontalCenter
    35. anchors.bottom: icon.bottom
    36. anchors.bottomMargin: 5
    37. font.bold: true
    38. font.pointSize: 14
    39. }
    40. MouseArea {
    41. id: mouseArea
    42. anchors.fill: parent
    43. hoverEnabled: true
    44. //接受左键和右键输入
    45. acceptedButtons: Qt.LeftButton | Qt.RightButton
    46. onClicked: {
    47. //左键点击
    48. if (mouse.button === Qt.LeftButton)
    49. {
    50. parent.clickedLeft()
    51. // console.log(button.text + " Left button click")
    52. }
    53. else if(mouse.button === Qt.RightButton)
    54. {
    55. parent.clickedRight()
    56. // console.log(button.text + " Right button click")
    57. }
    58. }
    59. //按下
    60. onPressed: {
    61. color = clr_click
    62. }
    63. //释放
    64. onReleased: {
    65. color = clr_enter
    66. parent.release()
    67. console.log("Release")
    68. }
    69. //指针进入
    70. onEntered: {
    71. color = clr_enter
    72. // console.log(button.text + " mouse entered")
    73. }
    74. //指针退出
    75. onExited: {
    76. color = clr_exit
    77. // console.log(button.text + " mouse exited")
    78. }
    79. }
    80. }

    调用:

    1. MyIconButton {
    2. x: mainWindow.width-40
    3. y: -8
    4. width: 20
    5. height: 20
    6. radius: 5
    7. id: btClose
    8. Image {
    9. id: name
    10. width: 20
    11. height:20
    12. source: "qrc:/image/close.png"
    13. }
    14. btn_txt: ""
    15. onClickedLeft: close()
    16. //onClickedRight: close()
    17. }

  • 相关阅读:
    mysql的sum求和函数求和性能优化
    【Linux入门】— 腾讯云服务器的搭建
    Java8-Optional工具类(有效防止空指针异常)
    Python 在问答频道中刷题积累到的小技巧(七)
    【论文翻译】使用变更数据捕获方法通过提取-转换-加载过程实时更新数据仓库
    win10&阿里云实现内网穿透#frp
    23.网络游戏逆向分析与漏洞攻防-网络通信数据包分析工具-实现配置工具数据结构
    大数据-之LibrA数据库系统告警处理(ALM-12052 TCP临时端口使用率超过阈值)
    cdh大数据平台中es安装、logstash安装、nginx安装、RTMP和FTP
    git config 查看,设置,删除项
  • 原文地址:https://blog.csdn.net/notfindjob/article/details/139797265
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号