Bug 378262 - krdb/kcminit sets wrong font for Qt4 applications on login
Summary: krdb/kcminit sets wrong font for Qt4 applications on login
Status: RESOLVED FIXED
Alias: None
Product: systemsettings
Classification: Applications
Component: krdb (show other bugs)
Version: 5.9.4
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: kdelibs bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-30 07:47 UTC by jingyu9575
Modified: 2017-07-16 18:51 UTC (History)
9 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jingyu9575 2017-03-30 07:47:14 UTC
The font used by Qt4 applications is always set to sans-serif 9pt, no matter what I select in system settings. Even if I set the font with qtconfig-qt4, it is reset on login. 

Steps to Reproduce: 
1) In system settings, set system font to MSYH 10pt (for example). 
2) Open a Qt4 application such as VLC. The font used is sans-serif 9pt.
3) In qtconfig-qt4, set font to MSYH 10pt.
4) Open the Qt4 application. The font used is MSYH 10pt.
5) Logout and login. Open the Qt4 application. The font used is again sans-serif 9pt.

Actual Results:
Qt4 applications use sans-serif 9pt at 2) and 5).

Expected Results:
Qt4 applications use MSYH 10pt, as configured in system settings.


Additional Information:

The config file that Qt4 applications use is ~/.config/Trolltech.conf. On login, kcminit (kcminit style) writes KDE5 settings to this file. In plasma-desktop/kcms/krdb/krdb.cpp, function applyQtSettings:

    settings.setValue(QStringLiteral("/qt/font"), QFontDatabase::systemFont(QFontDatabase::GeneralFont).toString());

Qt's default font is written to Trolltech.conf, which is supposed to be the font set in system settings on KDE5. However, this is launched by kcminit, which has plasma-workspace/startkde/kcminit/main.cpp, function kdemain:

    QGuiApplication::setDesktopSettingsAware(false);
    QGuiApplication app(argc, argv);

Without desktopSettingsAware, Qt's default font is forced to be sans-serif 9pt, which is then written to Trolltech.conf and causes this bug. 

Suggested fix: use KDE config to get the font instead of QFontDatabase::systemFont.


--- a/krdb.cpp	2017-03-21 22:00:06.000000000 +0800
+++ b/krdb.cpp	2017-03-30 15:44:20.103183732 +0800
@@ -178,10 +178,13 @@
 static void applyQtSettings( KSharedConfigPtr kglobalcfg, QSettings& settings )
 {
   /* export font settings */
-  settings.setValue(QStringLiteral("/qt/font"), QFontDatabase::systemFont(QFontDatabase::GeneralFont).toString());
+  KConfigGroup kdeCfgGroup(kglobalcfg, "General");
+  QString font = kdeCfgGroup.readEntry("font", QString());
+  settings.setValue(QStringLiteral("/qt/font"), !font.isEmpty() ? font :
+    QFontDatabase::systemFont(QFontDatabase::GeneralFont).toString());
 
   /* export effects settings */
-  KConfigGroup kdeCfgGroup(kglobalcfg, "General");
+  
   bool effectsEnabled = kdeCfgGroup.readEntry("EffectsEnabled", false);
   bool fadeMenus = kdeCfgGroup.readEntry("EffectFadeMenu", false);
   bool fadeTooltips = kdeCfgGroup.readEntry("EffectFadeTooltip", false);


Or remove that QGuiApplication::setDesktopSettingsAware(false).
Comment 1 jingyu9575 2017-03-30 07:50:29 UTC
A similar report: https://forum.kde.org/viewtopic.php?f=289&t=139158
Comment 2 Rex Dieter 2017-03-30 12:55:08 UTC
Do you have the kde4 platform plugin installed (from kde-workspace-4.x)?  I suspect that may be required (desirable?) to make this work better too.
Comment 3 jingyu9575 2017-03-30 16:00:23 UTC
(In reply to Rex Dieter from comment #2)
> Do you have the kde4 platform plugin installed (from kde-workspace-4.x)?  I
> suspect that may be required (desirable?) to make this work better too.

I can't find this package in Arch repo. KDE4 applications have right fonts, the problem is with other Qt4 applications like vlc-qt4.
Comment 4 Rex Dieter 2017-03-30 16:02:32 UTC
It's a Qt4 platform plugin, it's purpose is to provide a better uniform experience for Qt4-only apps.  (Similar to what plasma-integration provides for pure Qt5 applications).
Comment 5 jingyu9575 2017-03-30 18:29:10 UTC
(In reply to Rex Dieter from comment #4)
> It's a Qt4 platform plugin, it's purpose is to provide a better uniform
> experience for Qt4-only apps.  (Similar to what plasma-integration provides
> for pure Qt5 applications).

I searched the Arch repo but still cannot find it. I tried installing a rpm found on the Internet, which contains /usr/lib64/kde4/plugins/gui_platform/libkde.so, but nothing changes. Could you please list the file names/paths provided by this plugin package?
Comment 6 Rex Dieter 2017-03-30 18:31:22 UTC
libkde.so is it
Comment 7 Maciej Mrozowski 2017-04-10 15:42:51 UTC
I can confirm this bug on Gentoo earlier and recently also on Fedora 25 (observed during update of kf5-5.32 to 5.33 and plasma-5.8.6 to 5.9.4)

KDE4 plarform plugin is of course installed

[mrozowsk@cnu420dqzs ~]$ rpm -ql kde-platform-plugin 
/usr/lib64/kde4/plugins/gui_platform/libkde.so

When straced, pure Qt4 apps do load that plugin so QT4 plugin path is also set correctly.
Comment 8 Wolfgang Bauer 2017-06-10 15:14:17 UTC
Same here on openSUSE with the latest Qt5, KF5 and Plasma.

KDE4 applications do use the font from KDE4's kdeglobals (which is correctly synced), but plain Qt4 applications use the font specified in Trolltech.conf (which gets set to "Sans Serif 9" on every login to Plasma5).
Comment 9 boospy 2017-06-21 15:53:41 UTC
Same here on KDE Neon 5.10.
Comment 10 Kai Uwe Broulik 2017-06-30 12:19:19 UTC
Git commit 978700d9b65b6118e93a87bc7fbe9c113ca7d2ab by Kai Uwe Broulik.
Committed on 30/06/2017 at 12:16.
Pushed by broulik into branch 'master'.

[KRDB] Read kdeglobals font and fallback to hardcoded default if neccessary

kcminit is non-desktopSettingsAware (for performance) which will keep it from loading
our platform theme. This also means that QFontDatabase also won't know our font settings.

Based on a patch by jingyu9575, thanks.

M  +13   -2    kcms/krdb/krdb.cpp

https://commits.kde.org/plasma-desktop/978700d9b65b6118e93a87bc7fbe9c113ca7d2ab
Comment 11 boospy 2017-07-08 23:05:10 UTC
When is it planed to go to kdeneon?

Thanks
Comment 12 boospy 2017-07-15 23:13:09 UTC
Still not in KDE-Neon ;( 


Best Regards
Comment 13 Kai Uwe Broulik 2017-07-15 23:19:08 UTC
This is master branch ie. Plasma 5.11 material
Comment 14 boospy 2017-07-16 18:51:19 UTC
Oh... ok. Thanks for the information.