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 811 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 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?

    raven-worxR 1 Reply Last reply
    0
    • P pkli

      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?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on 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
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #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

        • Login

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