2018-10-06 19:12:05 +00:00
|
|
|
import QtQuick 2.11
|
|
|
|
import QtQuick.Controls 2.2
|
|
|
|
|
|
|
|
// https://stackoverflow.com/questions/45029968/how-do-i-set-the-combobox-width-to-fit-the-largest-item
|
|
|
|
ComboBox {
|
2018-10-06 19:59:59 +00:00
|
|
|
property int textWidth
|
2018-10-06 19:12:05 +00:00
|
|
|
|
2018-10-06 19:59:59 +00:00
|
|
|
implicitWidth: leftPadding + textWidth + indicator.width + rightPadding
|
2018-10-06 19:12:05 +00:00
|
|
|
|
|
|
|
TextMetrics {
|
2018-10-06 19:41:55 +00:00
|
|
|
id: popupMetrics
|
2018-10-06 19:12:05 +00:00
|
|
|
}
|
|
|
|
|
2018-10-06 19:41:55 +00:00
|
|
|
TextMetrics {
|
|
|
|
id: textMetrics
|
2018-10-06 19:12:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We call this every time the options change (and init)
|
|
|
|
// so we can adjust the combo box width here too
|
|
|
|
onActivated: {
|
2018-10-13 02:19:33 +00:00
|
|
|
textMetrics.font = font
|
|
|
|
popupMetrics.font = popup.font
|
2018-10-06 19:59:59 +00:00
|
|
|
textWidth = 0
|
2018-10-06 19:12:05 +00:00
|
|
|
for (var i = 0; i < count; i++){
|
|
|
|
textMetrics.text = textAt(i)
|
2018-10-06 19:41:55 +00:00
|
|
|
popupMetrics.text = textAt(i)
|
2018-10-06 19:59:59 +00:00
|
|
|
textWidth = Math.max(textMetrics.width, textWidth)
|
|
|
|
textWidth = Math.max(popupMetrics.width, textWidth)
|
2018-10-06 19:12:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|