Draw the indicator for combobox to ensure it looks the same on all platforms.

This commit is contained in:
Adam Treat 2023-05-31 19:55:16 -04:00
parent 1370995b92
commit 220e5547db

View File

@ -3,6 +3,7 @@ import QtQuick.Controls
import QtQuick.Controls.Basic import QtQuick.Controls.Basic
ComboBox { ComboBox {
id: comboBox
font.pixelSize: theme.fontSizeLarge font.pixelSize: theme.fontSizeLarge
spacing: 0 spacing: 0
padding: 10 padding: 10
@ -50,6 +51,33 @@ ComboBox {
color: theme.backgroundDark color: theme.backgroundDark
} }
} }
indicator: Canvas {
id: canvas
x: comboBox.width - width - comboBox.rightPadding
y: comboBox.topPadding + (comboBox.availableHeight - height) / 2
width: 12
height: 18
contextType: "2d"
Connections {
target: comboBox
function onPressedChanged() { canvas.requestPaint(); }
}
onPaint: {
context.reset();
context.lineWidth = 2;
context.moveTo(0, height / 2 - 2);
context.lineTo(width / 2, 0);
context.lineTo(width, height / 2 - 2);
context.moveTo(0, height / 2 + 2);
context.lineTo(width / 2, height);
context.lineTo(width, height / 2 + 2);
context.strokeStyle = comboBox.pressed ? theme.textAccent : theme.mutedTextColor;
context.stroke();
}
}
background: Rectangle { background: Rectangle {
color: theme.backgroundDark color: theme.backgroundDark
radius: 10 radius: 10