UserComboBox.qml 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import QtQuick 2.12
  2. import QtQuick.Controls 2.12
  3. ComboBox {
  4. id: control
  5. property var bgColor
  6. font.bold: true
  7. font.pixelSize: 20
  8. delegate: ItemDelegate {
  9. width: control.width
  10. height: control.height
  11. contentItem: Text {
  12. text: modelData
  13. color: "black"
  14. font: control.font
  15. elide: Text.ElideRight
  16. verticalAlignment: Text.AlignVCenter
  17. }
  18. highlighted: control.highlightedIndex === index
  19. }
  20. indicator: Canvas {
  21. id: canvas
  22. x: control.width - width - control.rightPadding
  23. y: control.topPadding + (control.availableHeight - height) / 2
  24. width: 12
  25. height: 8
  26. contextType: "2d"
  27. Connections {
  28. target: control
  29. function onPressedChanged() { canvas.requestPaint(); }
  30. }
  31. onPaint: {
  32. context.reset();
  33. context.moveTo(0, 0);
  34. context.lineTo(width, 0);
  35. context.lineTo(width / 2, height);
  36. context.closePath();
  37. //context.fillStyle = control.pressed ? "red" : "green";
  38. context.fillStyle ="gray"
  39. context.fill();
  40. }
  41. }
  42. contentItem: Text {
  43. leftPadding: 5
  44. rightPadding: control.indicator.width + control.spacing
  45. text: control.displayText
  46. font: control.font
  47. color: "black"
  48. //color: control.pressed ? "#17a81a" : "#21be2b"
  49. verticalAlignment: Text.AlignVCenter
  50. elide: Text.ElideRight
  51. }
  52. background: Rectangle {
  53. implicitWidth: control.width-2
  54. implicitHeight: control.height-2
  55. color: bgColor
  56. //border.color: control.pressed ? "#17a81a" : "#21be2b"
  57. //border.width: control.visualFocus ? 2 : 0
  58. radius: 3
  59. }
  60. popup: Popup {
  61. y: control.height - 1
  62. width: control.width
  63. implicitHeight: contentItem.implicitHeight
  64. padding: 1
  65. contentItem: ListView {
  66. clip: true
  67. implicitHeight: contentHeight+3
  68. model: control.popup.visible ? control.delegateModel : null
  69. currentIndex: control.highlightedIndex
  70. ScrollIndicator.vertical: ScrollIndicator { }
  71. }
  72. background: Rectangle {
  73. border.color: "gray"//"#21be2b"
  74. radius: 2
  75. opacity:1.0
  76. }
  77. }
  78. }