|
| 1 | +import QtQuick 2.9 |
| 2 | +import QtQuick.Controls 2.0 |
| 3 | +import QtQuick.Layouts 1.3 |
| 4 | +ComboBox { |
| 5 | + id: root |
| 6 | + property color checkedColor: "#dde4de" |
| 7 | + |
| 8 | + delegate:ItemDelegate { |
| 9 | + id:itemDelegate |
| 10 | + property string iconRectIcon: iconName ? iconName : "" |
| 11 | + |
| 12 | + width: root.width * 1.4 |
| 13 | + height: 40 |
| 14 | + hoverEnabled: true |
| 15 | + focus: true |
| 16 | + |
| 17 | + background: Rectangle{ |
| 18 | + color: itemDelegate.hovered ? "blue" : "transparent" |
| 19 | + anchors.fill: parent |
| 20 | + radius: 8 |
| 21 | + } |
| 22 | + |
| 23 | + RowLayout { |
| 24 | + Layout.alignment: Qt.AlignVCenter |
| 25 | + width: parent.width |
| 26 | + height: parent.height |
| 27 | + anchors.fill: parent |
| 28 | + spacing: 10 |
| 29 | + Layout.leftMargin: 10 |
| 30 | + Layout.rightMargin: 10 |
| 31 | + |
| 32 | + Label { |
| 33 | + opacity: 0.87 |
| 34 | + font.pointSize: 12 |
| 35 | + text: name |
| 36 | + Layout.fillWidth: true |
| 37 | + font.weight: Font.Medium |
| 38 | + verticalAlignment: Image.AlignVCenter |
| 39 | + Layout.alignment: Qt.AlignVCenter |
| 40 | + color: itemDelegate.hovered ? "white" : Qt.darkGray |
| 41 | + Layout.leftMargin: 10 |
| 42 | + } |
| 43 | + |
| 44 | + Label { |
| 45 | + opacity: 0.87 |
| 46 | + font.pointSize: 12 |
| 47 | + text: "✅" |
| 48 | + visible: root.currentIndex == index |
| 49 | + Layout.fillWidth: true |
| 50 | + font.weight: Font.Medium |
| 51 | + verticalAlignment: Image.AlignVCenter |
| 52 | + horizontalAlignment: Image.AlignRight |
| 53 | + Layout.alignment: Qt.AlignVCenter |
| 54 | + Layout.rightMargin: 10 |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + } |
| 59 | + |
| 60 | + indicator: Canvas { |
| 61 | + id: canvas |
| 62 | + x: root.width - width - 10 |
| 63 | + y: (root.availableHeight - height) / 2 |
| 64 | + width: 12 |
| 65 | + height: 8 |
| 66 | + contextType: "2d" |
| 67 | + |
| 68 | + Connections { |
| 69 | + target: root |
| 70 | + function onPressedChanged(){ |
| 71 | + canvas.requestPaint() |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + onPaint: { |
| 76 | + context.reset(); |
| 77 | + context.moveTo(0, 0); |
| 78 | + context.lineTo(width, 0); |
| 79 | + context.lineTo(width / 2, height); |
| 80 | + context.closePath(); |
| 81 | + context.fillStyle = "white" |
| 82 | + context.fill(); |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + contentItem: Item { |
| 87 | + width: root.background.width - root.indicator.width - 10 |
| 88 | + height: root.background.height |
| 89 | + |
| 90 | + RowLayout { |
| 91 | + anchors.fill: parent |
| 92 | + spacing: 10 |
| 93 | + Label { |
| 94 | + opacity: 0.87 |
| 95 | + font.pointSize: 12 |
| 96 | + text: model.get(currentIndex).name |
| 97 | + Layout.fillWidth: true |
| 98 | + font.weight: Font.Medium |
| 99 | + verticalAlignment: Image.AlignVCenter |
| 100 | + Layout.alignment: Qt.AlignVCenter |
| 101 | + color: Qt.darkGray |
| 102 | + elide: Text.ElideRight |
| 103 | + Layout.leftMargin: 10 |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + } |
| 108 | + |
| 109 | + background: Rectangle { |
| 110 | + implicitWidth: 200 |
| 111 | + implicitHeight: 41 |
| 112 | + color: root.down ? Qt.darker(root.checkedColor, 1.2) : root.checkedColor |
| 113 | + radius: 4 |
| 114 | + } |
| 115 | + |
| 116 | + popup: Popup { |
| 117 | + y: root.height - 1 |
| 118 | + width: root.width * 1.5 |
| 119 | + implicitHeight: contentItem.implicitHeight > 250 ? 250 : contentItem.implicitHeight |
| 120 | + padding: 4 |
| 121 | + contentItem: ListView { |
| 122 | + leftMargin: 5 |
| 123 | + implicitHeight: contentHeight |
| 124 | + keyNavigationEnabled: true |
| 125 | + model: root.popup.visible ? root.delegateModel : null |
| 126 | + clip: true |
| 127 | + focus: true |
| 128 | + currentIndex: root.highlightedIndex |
| 129 | + } |
| 130 | + |
| 131 | + background: Rectangle { |
| 132 | + anchors.fill: parent |
| 133 | + color: "#dde4de" |
| 134 | + radius: 4 |
| 135 | + clip: true |
| 136 | + } |
| 137 | + } |
| 138 | +} |
0 commit comments