PDA

View Full Version : How to center text in QML combobox



QtBert
20th April 2020, 20:56
Hi,

I have the following code:



Window {
id: window
visible: true
width: 640
height: 480
title: qsTr("Hello World")

GroupBox {
id: groupBox
width: label1.width + comboBox.width + label2.width +25

height: comboBox.height * 3 + 25
font.pointSize: 14
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
title: qsTr("DDM")

Label {
id: label
text: qsTr("Limits centered on")
anchors.rightMargin: 5
anchors.right: comboBox.left
anchors.verticalCenter: comboBox.verticalCenter
}

SpinBox {
id: spinBox
width: 200
editable: true
value: 100
to: 200
anchors.top: comboBox.bottom
anchors.topMargin: 5
anchors.left: comboBox.left
}

ComboBox {
id: comboBox
x: label1.width
width: 200
font.pointSize: 14
model: ["DDM 0", "Mean value"]
delegate: ItemDelegate {
contentItem: Text {
font.pixelSize: 22
text: modelData
horizontalAlignment: Text.horizontalCenter
}
}
}

Label {
id: label1
text: qsTr("Reduced ICAO limits")
anchors.rightMargin: 5
anchors.right: spinBox.left
anchors.verticalCenter: spinBox.verticalCenter
}

Label {
id: label2
text: qsTr("%")
anchors.leftMargin: 5
anchors.left: spinBox.right
anchors.verticalCenter: spinBox.verticalCenter

}
}
}


I would like to center the text. How can I do?
A secondary question is:
I have set in the combobox font.pointSize: 14
Bust I have to set font.pointSize: 22 in the delegate to get the same size of the text. Why?

Thank you