Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How do I access / load icon in QtCreator ? From "theme path" to " theme name "?



  • Here is my sample code to access "New" icon.

    const QIcon newIcon = QIcon::fromTheme("document-new", QIcon(":/images/new.png"));

    I am looking for basic bluetooth icon.
    I know it exists in my system as "bluetooth.png".

    I can retrieve "theme" path

      qDebug() << QIcon::themeSearchPaths();
    

    How do I get form "theme path" to " theme name "?
    Or do I have to ?

    QIcon RTFM is not much help.

    THANKS


  • Moderators

    Freedesktop specification does not specify any icons for Bluetooth. So getting one through fromTheme() will not work.

    Looking through KDE code for bluedevil, I noticed these:

        if (deviceConnected) {
            return "preferences-system-bluetooth-activated";
        } else if (!btManager.bluetoothOperational) {
            return "preferences-system-bluetooth-inactive";
        }
        return "preferences-system-bluetooth";
    

    Source: https://github.com/KDE/bluedevil/blob/master/src/applet/package/contents/ui/logic.js

    I have no idea if it will work, but it might be worth a try.



  • @sierdzio Thanks.
    It looks as I could do this the "create your own icon" way so I can reuse existing QIcon code.

    I found few python code examples

    Basically use any "bluetooth.png" icon currently on my system.

    Still looking for some explanation why I need "theme".
    It looks as they are using "theme" as some kind of "chapter"... or directory.

    Basically - if I am looking for an icon to represent a "bullet train" - how do I correlate that to "theme"?


  • Moderators

    I don't understand the why you mention theme name at all, sorry. "fromTheme" simply means "give me an icon from system theme" or "give me a standard system icon". The method returns an icon (ready to use), not path - there is no need to convert icon to theme or anything like that. Or I'm missing your point.


Log in to reply