Fixed fontFamilyComboBox

This commit is contained in:
Diyou 2024-03-17 18:33:16 +01:00
parent ca95ddc64b
commit 94d85dbcc4
No known key found for this signature in database
GPG key ID: 74219FC76F60F354
2 changed files with 10 additions and 26 deletions

View file

@ -58,31 +58,6 @@ Item {
property int cfg_dateShadowXOffset property int cfg_dateShadowXOffset
property int cfg_dateShadowYOffset property int cfg_dateShadowYOffset
function fixFontFamilyChange(id, comboBox) {
// HACK by the time we populate our model and/or the ComboBox is finished the value is still undefined
if (id) {
for (var i = 0, j = fontsModel.count; i < j; ++i) {
if (fontsModel.get(i).value === id) {
comboBox.currentIndex = i
break
}
}
}
}
onCfg_clockFontFamilyChanged: {
fixFontFamilyChange(cfg_clockFontFamily, clockFontFamilyComboBox)
}
onCfg_dayFontFamilyChanged: {
fixFontFamilyChange(cfg_dayFontFamily, dayFontFamilyComboBox)
}
onCfg_dateFontFamilyChanged: {
fixFontFamilyChange(cfg_dateFontFamily, dateFontFamilyComboBox)
}
ListModel { ListModel {
id: fontsModel id: fontsModel
Component.onCompleted: { Component.onCompleted: {

View file

@ -44,7 +44,16 @@ QtLayouts.RowLayout {
QtLayouts.Layout.minimumWidth: Kirigami.Units.gridUnit * 10 QtLayouts.Layout.minimumWidth: Kirigami.Units.gridUnit * 10
model: fontModel model: fontModel
textRole: "text" textRole: "text"
currentIndex: fontValue currentIndex: getIdFromModel()
function getIdFromModel(){
for(var i = 0; i < model.count; i++){
if(model.get(i).value === fontValue){
return i;
}
}
return 0;
}
onCurrentIndexChanged: { onCurrentIndexChanged: {
var current = model.get(currentIndex) var current = model.get(currentIndex)