[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: QIcon: Fallback behavior if icon not in the curren theme
From:       Maurizio Berti <maurizio.berti () gmail ! com>
Date:       2023-07-07 17:00:33
Message-ID: CAPn+-XTeztWvsPJx7uYgse=8k1OjmY+8uWno0uZnNVL4oRpcHA () mail ! gmail ! com
[Download RAW message or body]

Qt already provides something similar in the static functions of QIcon:

- setFallbackSearchPaths()
<https://doc.qt.io/qt-5/qicon.html#setFallbackSearchPaths>
- setFallbackThemeName()
<https://doc.qt.io/qt-5/qicon.html#setFallbackThemeName>

The QStyle StandardPixmap enum is not used for standard QIcons, as that's
not their intended purpose and they are actually just a few (~60), while a
full icon theme normally includes many more: the list of standard icons
from the freedesktop specification (
https://specifications.freedesktop.org/icon-naming-spec/latest/ar01s04.html
) contains almost 300 names.

Unfortunately, there is no absolute guarantee that an icon actually exists
for a given name in the installed themes, even if it's considered standard.
You can use QIcon.hasThemeIcon()
<https://doc.qt.io/qt-5/qicon.html#hasThemeIcon>, but once you know that
the icon doesn't exist, you're done.

Depending on the complexity of the program, you can consider providing your
own icon theme, eventually redistributing the one you like (as long as its
license allows it and is compatible with your project license) and use it
as a fallback, so that it will only be used whenever the installed icon
theme doesn't provide the required icon. The drawback of doing this is that
the icon styles may be inconsistent.

Cheers,
MaurizioB

Il giorno gio 6 lug 2023 alle ore 14:42 <c.buhtz@posteo.jp> ha scritto:

> Hello,
>
> am I right to say loading icons like this is usual and the recommended
> way (focusing on GNU Linux here)?
>
>      QIcon.fromTheme('media-playback-pause')
>
> How does Qt react if an Icon (by its name) is not available in the
> currents system default theme?
>
> Is there a fallback behavior? Maybe using Qt-inbuild icons from QStyle
> or an alternative theme?
>
> If there is such a behavior in Qt itself how can this be activated?
>
> If not I have to deal with it for my own of course.
>
> Kind
> Christian
>


-- 
È difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
http://www.jidesk.net

[Attachment #3 (text/html)]

<div dir="ltr"><div>Qt already provides something similar in the static functions of \
QIcon:</div><div><br></div><div>- <a \
href="https://doc.qt.io/qt-5/qicon.html#setFallbackSearchPaths">setFallbackSearchPaths()</a></div><div>- \
<a href="https://doc.qt.io/qt-5/qicon.html#setFallbackThemeName">setFallbackThemeName()</a><br></div><div><br></div><div>The \
QStyle StandardPixmap enum is not used for standard QIcons, as that&#39;s not their intended \
purpose and they are actually just a few (~60), while a full icon theme normally includes many \
more: the list of standard icons from the freedesktop specification ( <a \
href="https://specifications.freedesktop.org/icon-naming-spec/latest/ar01s04.html">https://specifications.freedesktop.org/icon-naming-spec/latest/ar01s04.html</a> \
) contains almost 300 names.</div><div><br></div><div>Unfortunately, there is no absolute \
guarantee that an icon actually exists for a given name in the installed themes, even if \
it&#39;s considered standard.</div><div>You can use <a \
href="https://doc.qt.io/qt-5/qicon.html#hasThemeIcon">QIcon.hasThemeIcon()</a>, but once you \
know that the icon doesn&#39;t exist, you&#39;re done.<br></div><div><br></div><div>Depending \
on the complexity of the program, you can consider providing your own icon theme, eventually \
redistributing the one you like (as long as its license allows it and is compatible with your \
project license) and use it as a fallback, so that it will only be used whenever the installed \
icon theme doesn&#39;t provide the required icon. The drawback of doing this is that the icon \
styles may be inconsistent.</div><div><br></div><div>Cheers,</div><div>MaurizioB<br></div></div><br><div \
class="gmail_quote"><div dir="ltr" class="gmail_attr">Il giorno gio 6 lug 2023 alle ore 14:42 \
&lt;<a href="mailto:c.buhtz@posteo.jp">c.buhtz@posteo.jp</a>&gt; ha \
scritto:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello,<br> <br>
am I right to say loading icons like this is usual and the recommended <br>
way (focusing on GNU Linux here)?<br>
<br>
        QIcon.fromTheme(&#39;media-playback-pause&#39;)<br>
<br>
How does Qt react if an Icon (by its name) is not available in the <br>
currents system default theme?<br>
<br>
Is there a fallback behavior? Maybe using Qt-inbuild icons from QStyle <br>
or an alternative theme?<br>
<br>
If there is such a behavior in Qt itself how can this be activated?<br>
<br>
If not I have to deal with it for my own of course.<br>
<br>
Kind<br>
Christian<br>
</blockquote></div><br clear="all"><br><span class="gmail_signature_prefix">-- </span><br><div \
dir="ltr" class="gmail_signature">È difficile avere una convinzione precisa quando si parla \
delle ragioni del cuore. - &quot;Sostiene Pereira&quot;, Antonio Tabucchi<br><a \
href="http://www.jidesk.net" target="_blank">http://www.jidesk.net</a></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic