trialuser02 / qt6ct

Qt6 Configuration Tool
BSD 2-Clause "Simplified" License
128 stars 10 forks source link

Option to disable font settings #46

Open cdock1029 opened 2 months ago

cdock1029 commented 2 months ago

I have an issue using qt6ct with qt creator. It correctly set's icon theme and color theme to make creator operate effectively on GNOME, including allowing me to style the designer UI in dark mode. But, it messes with the font within the editor.

Because the font setting is very one-size-fits all, it makes the normally bold elements within the editor go away so all text is "Regular" while the default behavior in Qt Creator is to make certain code elements bold.

If there was a checkbox to not write any font setting to the config nor have any default font setting injected into the Qt app, this problem would be solved, then I could still use the icon and color scheme settings alone but let Creator control fonts completely.

Desired font style with some bold elements:

Screenshot from 2024-04-27 21-42-24

Screenshot from 2024-04-27 21-42-33

qt6ct theme applied, all text "Regular":

Screenshot from 2024-04-27 21-39-52

Screenshot from 2024-04-27 21-43-50

ilya-fedin commented 2 months ago

qt6ct likely needs this: https://invent.kde.org/frameworks/kconfig/-/blob/master/src/gui/kconfiggroupgui.cpp#L153-170

loathingKernel commented 2 months ago

I can confirm that I have had similar issues with QtCreator, and sometimes unexpected crashes with qt5/6ct. In the case of QtCreator specifically I ended up disabling theming for it through qt6ct settings.

ilya-fedin commented 2 months ago

Perhaps this (mirroring the KDE code) would fix both problems and get rid of the need to disable font settings:

diff --git a/src/qt6ct/fontspage.cpp b/src/qt6ct/fontspage.cpp
index 5113edd..f0b95d5 100644
--- a/src/qt6ct/fontspage.cpp
+++ b/src/qt6ct/fontspage.cpp
@@ -70,11 +70,20 @@ void FontsPage::onFontChangeRequested(QWidget *widget)
 {
     bool ok = false;
     QFont font = QFontDialog::getFont (&ok, widget->font(), this);
-    if(ok)
+    if(!ok)
     {
-        widget->setFont(font);
-        qobject_cast<QLabel*>(widget)->setText(font.family () + " " + QString::number(font.pointSize ()));
+        return;
     }
+    if(font.weight() == QFont::Normal
+        && (font.styleName() == QLatin1String("Regular")
+            || font.styleName() == QLatin1String("Normal")
+            || font.styleName() == QLatin1String("Book")
+            || font.styleName() == QLatin1String("Roman")))
+    {
+        font.setStyleName(QString());
+    }
+    widget->setFont(font);
+    qobject_cast<QLabel*>(widget)->setText(font.family () + " " + QString::number(font.pointSize ()));
 }

 void FontsPage::readSettings()

Apply the patch, re-set the font settings and fonts should have the proper bold-ness.