Commit 1e2005b6 authored by DoinLakeFlyer's avatar DoinLakeFlyer

parent 956f4a86
...@@ -34,17 +34,26 @@ T.ComboBox { ...@@ -34,17 +34,26 @@ T.ComboBox {
property bool sizeToContents: false property bool sizeToContents: false
property string alternateText: "" property string alternateText: ""
property var _qgcPal: QGCPalette { colorGroupEnabled: enabled } property var _qgcPal: QGCPalette { colorGroupEnabled: enabled }
property real _largestTextWidth: 0 property real _largestTextWidth: 0
property real _popupWidth: sizeToContents ? _largestTextWidth + leftPadding + rightPadding : control.width property real _popupWidth: sizeToContents ? _largestTextWidth + itemDelegateMetrics.leftPadding + itemDelegateMetrics.rightPadding : control.width
property bool _onCompleted: false
TextMetrics { TextMetrics {
id: textMetrics id: textMetrics
font: control.font font.family: control.font.family
font.pointSize: control.font.pointSize
} }
onModelChanged: { ItemDelegate {
if (sizeToContents) { id: itemDelegateMetrics
visible: false
font.family: control.font.family
font.pointSize: control.font.pointSize
}
function _adjustSizeToContents() {
if (_onCompleted && sizeToContents) {
_largestTextWidth = 0 _largestTextWidth = 0
for (var i = 0; i < model.length; i++){ for (var i = 0; i < model.length; i++){
textMetrics.text = model[i] textMetrics.text = model[i]
...@@ -53,6 +62,13 @@ T.ComboBox { ...@@ -53,6 +62,13 @@ T.ComboBox {
} }
} }
onModelChanged: _adjustSizeToContents()
Component.onCompleted: {
_onCompleted = true
_adjustSizeToContents()
}
// The items in the popup // The items in the popup
delegate: ItemDelegate { delegate: ItemDelegate {
width: _popupWidth width: _popupWidth
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment