• qml 实现csdn搜索框,无规则圆角


    效果如下

    代码

    1. import QtQuick 2.15
    2. import QtQuick.Window 2.15
    3. import QtQuick.Controls 2.15
    4. import QtQuick.Layouts 1.15
    5. import QtGraphicalEffects 1.15
    6. ApplicationWindow {
    7. width: 640
    8. height: 480
    9. visible: true
    10. title: qsTr("qml 实现csdn的搜索框,不规则圆角实现")
    11. background: Rectangle{
    12. anchors.fill: parent
    13. color:"White"
    14. }
    15. Rectangle
    16. {
    17. id:searchBar
    18. anchors.centerIn: parent
    19. width:400
    20. height: 35
    21. border.color: "#fc5531"
    22. border.width: 1
    23. radius: searchBar.height / 2
    24. TextInput {
    25. anchors.leftMargin: 20
    26. anchors.right: btn.left
    27. anchors.left: parent.left
    28. font.pointSize: 12
    29. color: "Black"
    30. y:8
    31. maximumLength: 30
    32. focus: true
    33. MouseArea {
    34. anchors.fill: parent
    35. hoverEnabled: true
    36. onEntered: {
    37. searchBar.border.color = "#fc1944"
    38. }
    39. onExited: {
    40. searchBar.border.color = "#fc5531"
    41. }
    42. }
    43. }
    44. // right button #fc1944
    45. Rectangle {
    46. id:btn
    47. width: 80
    48. height: searchBar.height
    49. anchors.right: parent.right
    50. anchors.top: parent.top
    51. color: "#fc5531"
    52. layer.enabled: true
    53. layer.effect: OpacityMask{
    54. maskSource: Rectangle{
    55. width: 80
    56. height: btn.height
    57. radius: btn.height / 2
    58. //左侧
    59. Rectangle{
    60. width: 20
    61. height: btn.height
    62. }
    63. }
    64. }
    65. Image {
    66. id: image_search
    67. width: 20
    68. height:20
    69. x:10
    70. anchors.verticalCenter: parent.verticalCenter
    71. source: "qrc:/res/img/search.png"
    72. }
    73. Text {
    74. id: searchTxt
    75. color: "White"
    76. text: qsTr("搜索")
    77. anchors.verticalCenter: parent.verticalCenter
    78. anchors.left:image_search.right
    79. anchors.leftMargin: 1
    80. font.pointSize: 12
    81. font.bold: true
    82. }
    83. MouseArea {
    84. anchors.fill: parent
    85. hoverEnabled: true
    86. onEntered: {
    87. btn.color = "#fc1944"
    88. }
    89. onExited: {
    90. btn.color = "#fc5531"
    91. }
    92. }
    93. }
    94. }
    95. }

  • 相关阅读:
    win10 ISO
    update_engine-FilesystemVerifierAction和PostinstallRunnerAction
    留存计算方式
    React UI组件库——如何快速实现antd的按需引入和自定义主题
    html 动态设置下拉选项
    LabVIEW LINX Toolkit控制Arduino设备(拓展篇—1)
    [项目管理-7]:软硬件项目管理 - 项目采购管理 (物)
    parallelStream并行流性能
    安装SQL Server详细教程
    Mysql编译安装和yum安装
  • 原文地址:https://blog.csdn.net/ruglcc/article/details/125424527