From 206dd07eebed9375acb1726a016c58cdb6f02c45 Mon Sep 17 00:00:00 2001 From: Liu Zhangjian Date: Mon, 2 Dec 2024 17:11:08 +0800 Subject: [PATCH] fix: [fontcolorwidget] Fix font selection and display issues Fixed font selection and display issues in FontColorWidget by: - Making font combo box non-editable to prevent invalid font selections - Using currentText() instead of currentFont().family() for more reliable font name retrieval - Ensuring consistent font name handling across the widget The changes improve font selection reliability and prevent potential issues with font family name mismatches. Log: Fix font selection and display issues in FontColorWidget --- src/plugins/codeeditor/gui/settings/fontcolorwidget.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/plugins/codeeditor/gui/settings/fontcolorwidget.cpp b/src/plugins/codeeditor/gui/settings/fontcolorwidget.cpp index c39284e80..2e901d5a5 100644 --- a/src/plugins/codeeditor/gui/settings/fontcolorwidget.cpp +++ b/src/plugins/codeeditor/gui/settings/fontcolorwidget.cpp @@ -50,6 +50,7 @@ void FontColorWidgetPrivate::initUI() QLabel *infoLabel = new QLabel(FontColorWidget::tr("Font"), q); fontComboBox = new DFontComboBox(q); fontComboBox->setFontFilters(QFontComboBox::MonospacedFonts); + fontComboBox->setEditable(false); fontSizeComboBox = new QComboBox(q); fontSizeComboBox->setMinimumWidth(100); @@ -99,7 +100,7 @@ QWidget *FontColorWidgetPrivate::createItem(const QString &name, QWidget *widget QList FontColorWidgetPrivate::pointSizesForSelectedFont() const { QFontDatabase db; - const QString familyName = fontComboBox->currentFont().family(); + const QString familyName = fontComboBox->currentText(); QList sizeLst = db.pointSizes(familyName); if (!sizeLst.isEmpty()) return sizeLst; @@ -167,14 +168,14 @@ void FontColorWidget::setUserConfig(const QMap &map) void FontColorWidget::getUserConfig(QMap &map) { QVariantMap fontMap; - fontMap.insert(Key::FontFamily, d->fontComboBox->currentFont().family()); + fontMap.insert(Key::FontFamily, d->fontComboBox->currentText()); fontMap.insert(Key::FontSize, d->fontSizeComboBox->currentText().toInt()); fontMap.insert(Key::FontZoom, d->zoomSpinBox->value()); map.insert(Group::FontGroup, fontMap); EditorSettings::instance()->setValue(Node::FontColor, Group::FontGroup, Key::FontFamily, - d->fontComboBox->currentFont().family()); + d->fontComboBox->currentText()); EditorSettings::instance()->setValue(Node::FontColor, Group::FontGroup, Key::FontSize, d->fontSize); EditorSettings::instance()->setValue(Node::FontColor, Group::FontGroup, Key::FontZoom, d->zoomSpinBox->value()); }