Include the indicator in combo box width
This commit is contained in:
parent
7d1ecc8d82
commit
82a87e96b3
1 changed files with 5 additions and 5 deletions
|
|
@ -3,9 +3,9 @@ import QtQuick.Controls 2.2
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/45029968/how-do-i-set-the-combobox-width-to-fit-the-largest-item
|
// https://stackoverflow.com/questions/45029968/how-do-i-set-the-combobox-width-to-fit-the-largest-item
|
||||||
ComboBox {
|
ComboBox {
|
||||||
property int comboBoxWidth
|
property int textWidth
|
||||||
|
|
||||||
width: comboBoxWidth + 2*leftPadding + 2*rightPadding
|
implicitWidth: leftPadding + textWidth + indicator.width + rightPadding
|
||||||
|
|
||||||
TextMetrics {
|
TextMetrics {
|
||||||
id: popupMetrics
|
id: popupMetrics
|
||||||
|
|
@ -20,12 +20,12 @@ ComboBox {
|
||||||
// We call this every time the options change (and init)
|
// We call this every time the options change (and init)
|
||||||
// so we can adjust the combo box width here too
|
// so we can adjust the combo box width here too
|
||||||
onActivated: {
|
onActivated: {
|
||||||
comboBoxWidth = 0
|
textWidth = 0
|
||||||
for (var i = 0; i < count; i++){
|
for (var i = 0; i < count; i++){
|
||||||
textMetrics.text = textAt(i)
|
textMetrics.text = textAt(i)
|
||||||
popupMetrics.text = textAt(i)
|
popupMetrics.text = textAt(i)
|
||||||
comboBoxWidth = Math.max(textMetrics.width, comboBoxWidth)
|
textWidth = Math.max(textMetrics.width, textWidth)
|
||||||
comboBoxWidth = Math.max(popupMetrics.width, comboBoxWidth)
|
textWidth = Math.max(popupMetrics.width, textWidth)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue