DynamicGroupBox.qml 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import QtQuick 2.15
  2. import QtQuick.Controls 2.14
  3. import QtGraphicalEffects 1.14
  4. GroupBox {
  5. property var radiusVal: 6 // 圆角值
  6. property var borderWidth: 1 // 边框宽度
  7. property var borderColor: "#97C4F5" // 边框颜色
  8. property var titleColor: "#2359B7" // 标题颜色
  9. property var titleLeftBkColor: "#C9DDF8" // 标题最左侧背景色
  10. property var titleRightBkColor: "#F7FAFF" // 标题最右侧颜色
  11. property var titleTopPadding: 3 // 标题的顶部内边距
  12. property var contentBkColor: "#77F0F6FF" // 内容背景色
  13. property var titleFontPixel: 24
  14. id: control
  15. title: qsTr("GroupBox")
  16. background: Rectangle {
  17. anchors.fill: control
  18. radius: radiusVal
  19. border.color: borderColor
  20. clip: true
  21. Item {
  22. x: borderWidth
  23. y: borderWidth
  24. width: parent.width - borderWidth * 2
  25. height: control.topPadding - control.bottomPadding - borderWidth * 2 + titleTopPadding * 2
  26. clip: true
  27. Rectangle { // 设置标题的背景色
  28. anchors.fill: parent
  29. color: "#228833"
  30. LinearGradient {
  31. anchors.fill: parent
  32. source: parent
  33. start: Qt.point(0, 0)
  34. end: Qt.point(parent.width, 0)
  35. gradient: Gradient {
  36. GradientStop { position: 0.0; color: titleLeftBkColor }
  37. GradientStop { position: 1.0; color: titleRightBkColor }
  38. }
  39. }
  40. }
  41. }
  42. Rectangle { // 设置内容的背景色
  43. x: 1
  44. y: control.topPadding - control.bottomPadding - borderWidth * 2 + titleTopPadding * 2
  45. width: parent.width - borderWidth * 2
  46. height: parent.height - control.topPadding + control.bottomPadding - borderWidth * 2 - titleTopPadding * 2
  47. color: contentBkColor
  48. }
  49. }
  50. label: Label { // 设置title的属性
  51. y: titleTopPadding
  52. x: control.leftPadding
  53. width: control.availableWidth
  54. text: control.title
  55. color: titleColor
  56. elide: Text.ElideRight
  57. font.pixelSize: titleFontPixel
  58. }
  59. }