[.qml+python3] How to read Icons KCM configured sizes?

I have a python3+qml application that needs to use the system icon set. Consequently, I want to be able to set the icon size per the preferences set by the user in KDE Plasma’s Icons KCM.

Are you using Kirigami? If you are using kirigami all the Kirigami components that use icons will use the icons from the system theme and also the size will be according to what is set in the system settings.

I’m not an expert btw

1 Like

I was just using QML, since I thought that that would be easier to learn than QML with Kirigami. Am I mistaken?

Might be similar to [.qml+python3] How to determine whether icons are enabled? - #6 by ngraham

These settings have been removed in Plasma 6, so the answer now is that there is no way to read them.

1 Like

@ngraham, so how do most KDE apps consistently size themselves based upon the display scale? There must be something communally responsible that’s ultimately hooked into, else every application would look as if its iconography had been randomly sized.

For instance, when I want to use iconography in my Qt applications, do I access a separate program or Qt / KDE Frameworks library or function to resize them?

Use the standard icon sizes from KIconThemes, available in on the QML side via Kirigami.Units.iconSizes.[stuff]. You’ll see these all over the code of any KDE app.

2 Likes

Thanks, @ngraham. I guess this was X/Y again, right?


If I find an application which doesn’t appear to use sensibly sized iconography, is this what I should request they use?

I used to ask them to adhere to preferences like

Basically, if an app doesn’t use what you believe to be the correct icon size, it’s something that will have to be changed in the app’s code if the developers agree with you that the size is wrong. It’s generally really easy to do this, so changes can be made quickly if there’s agreement on it.

There are two ways for this to be wrong in KDE software or software targeting a Plasma environment that has access to KIconThemes or Kirigami:

  • Using a hardcoded pixel size for icons rather than one of the standard icon sizes. These standard sizes have names like small, smallMedium, medium, large, and so on.
  • Using a standard icon size that’s inappropriate for the context. For example using large (which is 48px) in list items, when it should instead be smallMedium (which is 22px) for single-line-of-text list items, or medium (which is 32px) for two-or-more-line-of-text list items.

For large-ish icons just on the page itself (as opposed to inside a button, menu item, list item, etc) we don’t have any hard-and-fast rules for what size is correct, so it’s more of a judgement call based on “does it look good?”

Does that make sense?

1 Like

Perhaps I’ve been thinking about it differently to you. I’ve always used kcm_icons to force my icons to all be the same size. Perhaps that’s simply not supported anymore.

There’s nothing that ultimately synchronizes them between applications, then? That seems like somewhat of a retrograde step considering the deprecation of the manual icon size configurator.

I’ve always used kcm_icons to force my icons to all be the same size. Perhaps that’s simply not supported anymore.

Indeed, it’s not supported anymore, because it didn’t actually work for that purpose. Setting everything in there to be the same size would change some icons in some apps, but others would still be unchanged. The goal you were aiming for was not achievable.

There’s nothing that ultimately synchronizes them between applications, then? That seems like somewhat of a retrograde step considering the deprecation of the manual icon size configurator.

No. Even if this goal was achievable because literally every icon respected the old settings, the result would have been undesirable. Apps use different icon sizes in different contexts for a variety of reasons. Larger icons often simply look better than smaller icons when surrounded by a lot of whitespace, for example. Ultimately the app developer is in the best position to determine what the best size is for the icons that they use.

“Consistency” doesn’t mean “everything looks identical.” See Get Involved/Design/Frequently Discussed Topics - KDE Community Wiki

3 Likes

In this particular app (a Qt application vdu_controls, I was attempting to alter the icon sizes depending on DPI. But users may change scaling and font sizes, so just using DPI is perhaps not good enough.

I have since changed the code to modify icon sizes based on the fontmetric height of standard text, I think this might get the proportions right more often (plus there is already fallback user setting to turn off any attempt to proportion for DPI).

1 Like

Outside of graphics software, in my experience handling scaling manually is a recipe for things to end up looking bizarre.

In general I’d recommend using the KDE standard icon sizes if you’re using any KDE code. If this is a QML UI, You might be interested in Kirgami.IconSizes.sizeForLabels which is calculated to be the largest of the standard icon sizes that fits within a standard piece of text using the System’s standard font size.

3 Likes

The code attempts to be neutral, so no KDE code. I intend for it to run on any Linux desktop, but only test on KDE, gnome, Deepin, and Xfce. Although I normally use the default icon sizes, there are some compound custom widgets where the icons look a bit small if left to default. Looking up the default font height in pixels seems to be working OK. It’s a relatively small simple layout, so that helps.

I now use the same font-height metric to help calculate some minimum window and component sizes, that seems to have worked OK too.

But, yes, DPI/Scaling is a slippery area. I’m not too familiar with coding for varying DPI or high-DPI, but the resulting layout seems to be OK now. I’ve previously coded using device independent pixel sizes on Android, but I’ve mostly forgotten that experience and what advantages it had.