Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QIcon::fromTheme
Forum Updated to NodeBB v4.3 + New Features

QIcon::fromTheme

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MathiasGr
    wrote on last edited by MathiasGr
    #1

    I am getting crazy with QIcon::fromTheme()... My goal is to get "standard" icons on Linux (with KDE or Gnome) and fallback custom icons for all other platforms.

    So in my main(), I have the following code (here only shown for Windows, but the same is also defined for Mac):

    //for Linux, we keep the icon theme of the user
    #ifdef Q_OS_WIN
    	QIcon::setThemeName("flat-bw"); //we provide our own icons for MS Win / osX
    #endif
    

    Then in my /resources directory, I have a QRC file such as:

    <!DOCTYPE RCC><RCC version="1.0">
    <qresource prefix="icons/flat-bw">
    <file alias="index.theme">icons/flat-bw/index.theme</file>
    <file alias="48x48/document-open.png">icons/flat-bw/48x48/document-open.png</file>
    <file alias="48x48/application-exit.png">icons/flat-bw/48x48/application-exit.png</file>
    </qresource>
    </RCC>
    

    In my resources/icons/flat-bw directory, I have a "48x48" directory with the icons and an index.theme file such as:

    [Icon Theme]
    Name=flat-bw
    Comment=Breeze BW Icons
    Directories=48x48
    
    [48x48]
    Size=48
    Type=Fixed
    

    And finally, where I need an icon, I get it as:

    file_open_ini_ = new QAction(QIcon::fromTheme("document-open"), tr("&Open INI file"), menu_file);
    

    On Linux, it works great. It picks up the user-configured default theme. If I "force" it to take my custom icons (by calling "setThemeName"), it also works. But On Windows, there is no way to get any icon. If I set the icon with a path (such as QIcon::fromTheme(":icons/flat-bw/48x48/document-open.png")), then it works. If I try to define a fallback icon, it never calls the fallback.

    Would anybody have any idea what could be wrong or how to figure out what could be wrong? In the resource browser of QtCreator, I properly see my icons... If I print the icons search path, it starts with ":icons" so it should be OK...
    Thanks a lot for any tip!

    VRoninV 1 Reply Last reply
    0
    • M MathiasGr

      I am getting crazy with QIcon::fromTheme()... My goal is to get "standard" icons on Linux (with KDE or Gnome) and fallback custom icons for all other platforms.

      So in my main(), I have the following code (here only shown for Windows, but the same is also defined for Mac):

      //for Linux, we keep the icon theme of the user
      #ifdef Q_OS_WIN
      	QIcon::setThemeName("flat-bw"); //we provide our own icons for MS Win / osX
      #endif
      

      Then in my /resources directory, I have a QRC file such as:

      <!DOCTYPE RCC><RCC version="1.0">
      <qresource prefix="icons/flat-bw">
      <file alias="index.theme">icons/flat-bw/index.theme</file>
      <file alias="48x48/document-open.png">icons/flat-bw/48x48/document-open.png</file>
      <file alias="48x48/application-exit.png">icons/flat-bw/48x48/application-exit.png</file>
      </qresource>
      </RCC>
      

      In my resources/icons/flat-bw directory, I have a "48x48" directory with the icons and an index.theme file such as:

      [Icon Theme]
      Name=flat-bw
      Comment=Breeze BW Icons
      Directories=48x48
      
      [48x48]
      Size=48
      Type=Fixed
      

      And finally, where I need an icon, I get it as:

      file_open_ini_ = new QAction(QIcon::fromTheme("document-open"), tr("&Open INI file"), menu_file);
      

      On Linux, it works great. It picks up the user-configured default theme. If I "force" it to take my custom icons (by calling "setThemeName"), it also works. But On Windows, there is no way to get any icon. If I set the icon with a path (such as QIcon::fromTheme(":icons/flat-bw/48x48/document-open.png")), then it works. If I try to define a fallback icon, it never calls the fallback.

      Would anybody have any idea what could be wrong or how to figure out what could be wrong? In the resource browser of QtCreator, I properly see my icons... If I print the icons search path, it starts with ":icons" so it should be OK...
      Thanks a lot for any tip!

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      @MathiasGr said in QIcon::fromTheme:

      <qresource prefix="icons/flat-bw">

      try <qresource prefix="/icons/flat-bw"> instead

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      M 1 Reply Last reply
      1
      • VRoninV VRonin

        @MathiasGr said in QIcon::fromTheme:

        <qresource prefix="icons/flat-bw">

        try <qresource prefix="/icons/flat-bw"> instead

        M Offline
        M Offline
        MathiasGr
        wrote on last edited by
        #3

        @VRonin I was really hopeful, but it makes no difference. I don't understand why the handling of icons is not much better in Qt, this is a feature that is required for all GUIs...

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #4

          Did you re-run qmake after the change?

          This minimal example works for me, could you try it on your side?

          https://github.com/VSRonin/IconThemeTest

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          4
          • M Offline
            M Offline
            MathiasGr
            wrote on last edited by
            #5

            @VRonin Thanks a lot for the code example! It works, so I have to find what I do differently that makes the problem... I'll post the results here when I will have figured it out. Again, thanks a lot for the code example!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved