Programmatic color scheme change in QKdeTheme

David Redondo david at david-redondo.de
Tue Mar 11 08:39:07 GMT 2025


Am Montag, 10. März 2025, 19:24 schrieb Axel Spoerl:
> Hi David,
> 
> I just did some debugging to find out, how KDE Palettes are promoted to the QKdeTheme.
> The blunt answer is: They don't, and they have never been.
> 
> They were probably meant to be promoted at some point, because QKdeTheme implements an array of QPalette pointers (size == NPalettes == 17).
> So for each palette type, a new QPalette could be constructed from a KDE Palette. But that's not happening. The first record of the array is populated with default constructed QPalette, which is a fusion palette.
> All other records are initialized with nullptr and they remain like that throughout the life time of the QGuiApplication.
> 
> QKdeTheme just implements font handling. Color wise, QGuiApplications won't blend in with KDE palettes. They just stick with a default fusion palette.
> 
> That said: I think there's nothing needed right now. But we may want to pimp up QKdeTheme.
> The patch I mentioned factors it out from qgenericunixthemes.cpp. So enhancing the class will become a little easier.
> 

Maybe a reason that it doesn't do that much was that Plasma has its own QPT,
so there was never enough pressure to make it better since in the most cases an
application would not use QKDETheme except if it shipped its own Qt or
something similar.

I've written  very small program that prints the resulting QPalette from color
schemes. The output for BreezeLight and BreezeDark is as follows:

/usr/share/color-schemes/BreezeLight.colors
QPalette(resolve=0x7ffdffffefffff7f,"WindowText:[Active:#ff232629,Disabled:#ffa0a1a3,Inactive:#ff232629],Button:[Active:#fffcfcfc,Disabled:#fff0f0f0,Inactive:#fffcfcfc],Light:[Active:#ffffffff,Disabled:#ffffffff,Inactive:#ffffffff],Midlight:[Active:#fff6f7f7,Disabled:#ffebedee,Inactive:#fff6f7f7],Dark:[Active:#ff888e93,Disabled:#ff82878c,Inactive:#ff888e93],Mid:[Active:#ffc4c8cc,Disabled:#ffbbc0c5,Inactive:#ffc4c8cc],Text:[Active:#ff232629,Disabled:#ffaaabac,Inactive:#ff232629],ButtonText:[Active:#ff232629,Disabled:#ffa8a9aa,Inactive:#ff232629],Base:[Active:#ffffffff,Disabled:#fff3f3f3,Inactive:#ffffffff],Window:[Active:#ffeff0f1,Disabled:#ffe3e5e7,Inactive:#ffeff0f1],Shadow:[Active:#ff474a4c,Disabled:#ff474a4c,Inactive:#ff474a4c],Highlight:[Active:#ff3daee9,Disabled:#ffe3e5e7,Inactive:#ffc2e0f5],HighlightedText:[Active:#ffffffff,Disabled:#ffa0a1a3,Inactive:#ff232629],Link:[Active:#ff2980b9,Disabled:#ffa3cae2,Inactive:#ff2980b9],LinkVisited:[Active:#ff9b59b6,Disabled:#ffd6bae1,Inactive:#ff9b59b6],AlternateBase:[Active:#fff7f7f7,Disabled:#ffebebeb,Inactive:#fff7f7f7],ToolTipBase:[Active:#fff7f7f7,Disabled:#fff7f7f7,Inactive:#fff7f7f7],ToolTipText:[Active:#ff232629,Disabled:#ff232629,Inactive:#ff232629],PlaceholderText:[Active:#ff707d8a,Disabled:#ffc2c8ce,Inactive:#ff707d8a],Accent:[Active:#ff3daee9,Disabled:#ffe3e5e7,Inactive:#ffc2e0f5]")

/usr/share/color-schemes/BreezeDark.colors
QPalette(resolve=0x7ffdffffefffff7f,"WindowText:[Active:#fffcfcfc,Disabled:#ff686a6c,Inactive:#fffcfcfc],Button:[Active:#ff292c30,Disabled:#ff272a2e,Inactive:#ff292c30],Light:[Active:#ff393e43,Disabled:#ff383d42,Inactive:#ff393e43],Midlight:[Active:#ff2e3337,Disabled:#ff2d3136,Inactive:#ff2e3337],Dark:[Active:#ff131516,Disabled:#ff121415,Inactive:#ff131516],Mid:[Active:#ff1c1f21,Disabled:#ff1b1d20,Inactive:#ff1c1f21],Text:[Active:#fffcfcfc,Disabled:#ff606263,Inactive:#fffcfcfc],ButtonText:[Active:#fffcfcfc,Disabled:#ff6d6f72,Inactive:#fffcfcfc],Base:[Active:#ff141618,Disabled:#ff131517,Inactive:#ff141618],Window:[Active:#ff202326,Disabled:#ff1f2124,Inactive:#ff202326],Shadow:[Active:#ff0e0f10,Disabled:#ff0d0e0f,Inactive:#ff0e0f10],Highlight:[Active:#ff3daee9,Disabled:#ff1f2124,Inactive:#ff1b4155],HighlightedText:[Active:#fffcfcfc,Disabled:#ff686a6c,Inactive:#fffcfcfc],Link:[Active:#ff1d99f3,Disabled:#ff164160,Inactive:#ff1d99f3],LinkVisited:[Active:#ff9b59b6,Disabled:#ff402b4c,Inactive:#ff9b59b6],AlternateBase:[Active:#ff1d1f22,Disabled:#ff1c1e20,Inactive:#ff1d1f22],ToolTipBase:[Active:#ff292c30,Disabled:#ff292c30,Inactive:#ff292c30],ToolTipText:[Active:#fffcfcfc,Disabled:#fffcfcfc,Inactive:#fffcfcfc],PlaceholderText:[Active:#ffa1a9b1,Disabled:#ff42464a,Inactive:#ffa1a9b1],Accent:[Active:#ff3daee9,Disabled:#ff1f2124,Inactive:#ff1b4155]")

The code that turns those color schemes into QPalettes is here: https://invent.kde.org/frameworks/kcolorscheme/-/blob/master/src/kcolorscheme.cpp#L580

David
-------------- next part --------------
A non-text attachment was scrubbed...
Name: printpalette.cpp
Type: text/x-c++src
Size: 285 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-devel/attachments/20250311/012d1acd/attachment.cpp>


More information about the kde-devel mailing list