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. How to properly support multiple icon sets in a Qt application
Forum Updated to NodeBB v4.3 + New Features

How to properly support multiple icon sets in a Qt application

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 807 Views 4 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.
  • P Offline
    P Offline
    pkli
    wrote on 6 Feb 2020, 08:31 last edited by
    #1

    Nowadays almost every application supports multiple themes. Most present here is a night / dark mode. Changing the look and feel of a Qt application seems to be straight forward and not too difficult at least color wise.

    But what about changing the icons on the fly?

    My story: I have an application written with Qt (QWidget based) which has QIcons for almost all QActions defined in the .ui file.

    What is the Qt way of changing the icons globally without needing to call myAction->setIcon(...) for every QAction?

    R 1 Reply Last reply 6 Feb 2020, 19:37
    0
    • P pkli
      6 Feb 2020, 08:31

      Nowadays almost every application supports multiple themes. Most present here is a night / dark mode. Changing the look and feel of a Qt application seems to be straight forward and not too difficult at least color wise.

      But what about changing the icons on the fly?

      My story: I have an application written with Qt (QWidget based) which has QIcons for almost all QActions defined in the .ui file.

      What is the Qt way of changing the icons globally without needing to call myAction->setIcon(...) for every QAction?

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 6 Feb 2020, 19:37 last edited by
      #2

      @pkli
      One way could be using stylesheets.
      Or since you anyway set your icons yourself, you could also implement a fancy custom event (link is rather old but still applicable) for icon change and ract on it in your widgets.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 6 Feb 2020, 23:23 last edited by mrjj 2 Jun 2020, 23:24
        #3

        Hi
        Using code to set icons, Qt has a system for themes.

        QDir::setSearchPaths("icons", QStringList() << ":/light");
        // OR QDir::setSearchPaths("icons", QStringList() << ":/dark");
          ui->pushButton->setIcon(QIcon("icons:12125.jpg"));
        

        same filename, but different folders. However, this doesn't work with Designer
        as far as i know/could make it work.

        You could also move the resource to be external
        If you have 2 icons folder like icon and darkicon.
        Then first compile the one res file
        Rename icon to icon_xxx and darkicon to icon.
        Then compile the second res file.
        (so the file is in same folders (icon) )

        Then in the app you can use
        QResource::registerResource
        to load either the dark or light res file.

        https://doc.qt.io/qt-5/resources.html

        However, this does require a restart of the app.

        1 Reply Last reply
        2

        1/3

        6 Feb 2020, 08:31

        • Login

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