2018-10-13 20:16:18 -07:00
|
|
|
import QtQuick 2.9
|
2018-10-06 12:12:05 -07:00
|
|
|
import QtQuick.Controls 2.2
|
|
|
|
|
2019-05-19 10:16:54 -07:00
|
|
|
import SdlGamepadKeyNavigation 1.0
|
|
|
|
|
2018-10-06 12:12:05 -07:00
|
|
|
// https://stackoverflow.com/questions/45029968/how-do-i-set-the-combobox-width-to-fit-the-largest-item
|
|
|
|
ComboBox {
|
2018-10-06 12:59:59 -07:00
|
|
|
property int textWidth
|
2020-05-10 11:12:37 -07:00
|
|
|
property int desiredWidth : leftPadding + textWidth + indicator.width + rightPadding
|
|
|
|
property int maximumWidth : parent.width
|
2018-10-06 12:12:05 -07:00
|
|
|
|
2020-05-10 11:12:37 -07:00
|
|
|
implicitWidth: desiredWidth < maximumWidth ? desiredWidth : maximumWidth
|
2018-10-06 12:12:05 -07:00
|
|
|
|
|
|
|
TextMetrics {
|
2018-10-06 12:41:55 -07:00
|
|
|
id: popupMetrics
|
2018-10-06 12:12:05 -07:00
|
|
|
}
|
|
|
|
|
2018-10-06 12:41:55 -07:00
|
|
|
TextMetrics {
|
|
|
|
id: textMetrics
|
2018-10-06 12:12:05 -07:00
|
|
|
}
|
|
|
|
|
2020-11-24 00:13:39 -06:00
|
|
|
function recalculateWidth() {
|
2018-10-12 19:19:33 -07:00
|
|
|
textMetrics.font = font
|
|
|
|
popupMetrics.font = popup.font
|
2018-10-06 12:59:59 -07:00
|
|
|
textWidth = 0
|
2018-10-06 12:12:05 -07:00
|
|
|
for (var i = 0; i < count; i++){
|
|
|
|
textMetrics.text = textAt(i)
|
2018-10-06 12:41:55 -07:00
|
|
|
popupMetrics.text = textAt(i)
|
2018-10-06 12:59:59 -07:00
|
|
|
textWidth = Math.max(textMetrics.width, textWidth)
|
|
|
|
textWidth = Math.max(popupMetrics.width, textWidth)
|
2018-10-06 12:12:05 -07:00
|
|
|
}
|
|
|
|
}
|
2019-05-19 10:16:54 -07:00
|
|
|
|
2020-11-24 00:13:39 -06:00
|
|
|
// We call this every time the options change (and init)
|
|
|
|
// so we can adjust the combo box width here too
|
|
|
|
onActivated: recalculateWidth()
|
|
|
|
|
2019-05-19 10:16:54 -07:00
|
|
|
popup.onAboutToShow: {
|
|
|
|
// Switch to normal navigation for combo boxes
|
|
|
|
SdlGamepadKeyNavigation.setUiNavMode(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
popup.onAboutToHide: {
|
|
|
|
SdlGamepadKeyNavigation.setUiNavMode(true)
|
|
|
|
}
|
2018-10-06 12:12:05 -07:00
|
|
|
}
|