Fix popup font resizing on macOS
This commit is contained in:
@@ -3,25 +3,29 @@ 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 modelWidth
|
property int comboBoxWidth
|
||||||
|
|
||||||
width: modelWidth + 2*leftPadding + 2*rightPadding
|
width: comboBoxWidth + 2*leftPadding + 2*rightPadding
|
||||||
|
|
||||||
|
TextMetrics {
|
||||||
|
id: popupMetrics
|
||||||
|
font: popup.font
|
||||||
|
}
|
||||||
|
|
||||||
TextMetrics {
|
TextMetrics {
|
||||||
id: textMetrics
|
id: textMetrics
|
||||||
font: parent.font
|
font: parent.font
|
||||||
}
|
}
|
||||||
|
|
||||||
onFontChanged: {
|
|
||||||
textMetrics.font = font
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
||||||
for (var i = 0; i < count; i++){
|
for (var i = 0; i < count; i++){
|
||||||
textMetrics.text = textAt(i)
|
textMetrics.text = textAt(i)
|
||||||
modelWidth = Math.max(textMetrics.width, modelWidth)
|
popupMetrics.text = textAt(i)
|
||||||
|
comboBoxWidth = Math.max(textMetrics.width, comboBoxWidth)
|
||||||
|
comboBoxWidth = Math.max(popupMetrics.width, comboBoxWidth)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user