2018-10-14 03:16:18 +00:00
|
|
|
import QtQuick 2.9
|
2018-10-06 19:12:05 +00:00
|
|
|
import QtQuick.Controls 2.2
|
|
|
|
|
2019-05-19 17:16:54 +00:00
|
|
|
import SdlGamepadKeyNavigation 1.0
|
|
|
|
|
2018-10-06 19:12:05 +00:00
|
|
|
// 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
|
2020-05-10 18:12:37 +00:00
|
|
|
property int desiredWidth : leftPadding + textWidth + indicator.width + rightPadding
|
|
|
|
property int maximumWidth : parent.width
|
2018-10-06 19:12:05 +00:00
|
|
|
|
2020-05-10 18:12:37 +00:00
|
|
|
implicitWidth: desiredWidth < maximumWidth ? desiredWidth : maximumWidth
|
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
|
|
|
}
|
|
|
|
|
2020-11-24 06:13:39 +00:00
|
|
|
function recalculateWidth() {
|
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
|
|
|
}
|
|
|
|
}
|
2019-05-19 17:16:54 +00:00
|
|
|
|
2020-11-24 06:13:39 +00: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 17:16:54 +00:00
|
|
|
popup.onAboutToShow: {
|
|
|
|
// Switch to normal navigation for combo boxes
|
|
|
|
SdlGamepadKeyNavigation.setUiNavMode(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
popup.onAboutToHide: {
|
|
|
|
SdlGamepadKeyNavigation.setUiNavMode(true)
|
|
|
|
}
|
2018-10-06 19:12:05 +00:00
|
|
|
}
|