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. Reload/change Icons on style change

Reload/change Icons on style change

Scheduled Pinned Locked Moved Solved General and Desktop
stylesresourcesicons
7 Posts 2 Posters 6.4k Views
  • 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.
  • ImunarI Offline
    ImunarI Offline
    Imunar
    wrote on last edited by A Former User
    #1

    Hi there,

    I've got a Qt application for Windows and Linux
    with two different styles ( a dark (night) and a light (day) style).
    For each style I've got Icons in their prefix inside the qt resource system

    The style changes as supposed and the Ui is redrawn,
    and I change the icon search path to the new prefix,
    but now I need to change all existing Icons to fit into the style.

    What I've seen:
    When the style sets an QIcon via stylesheet (as a special close button in a QTabWidget),
    a new QIcon will be created.
    When a view displays a Qt:IconRole the new Icon will be created (slow when the model contains to much data)
    But all older Icons will stay.

    Is there a way to reload all existing Icons with their new prefix (aliases where the same)
    or do I need to keep a system wide map of Icons and their icon path names to reload them when the style changes?

    Or is the only way to create an own icon theme with all icons on hard disk?

    Kind regards
    Imunar

    raven-worxR 1 Reply Last reply
    0
    • ImunarI Imunar

      Hi there,

      I've got a Qt application for Windows and Linux
      with two different styles ( a dark (night) and a light (day) style).
      For each style I've got Icons in their prefix inside the qt resource system

      The style changes as supposed and the Ui is redrawn,
      and I change the icon search path to the new prefix,
      but now I need to change all existing Icons to fit into the style.

      What I've seen:
      When the style sets an QIcon via stylesheet (as a special close button in a QTabWidget),
      a new QIcon will be created.
      When a view displays a Qt:IconRole the new Icon will be created (slow when the model contains to much data)
      But all older Icons will stay.

      Is there a way to reload all existing Icons with their new prefix (aliases where the same)
      or do I need to keep a system wide map of Icons and their icon path names to reload them when the style changes?

      Or is the only way to create an own icon theme with all icons on hard disk?

      Kind regards
      Imunar

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @Imunar
      When the icon comes from the style itself you do not have to change anything.

      For the model case, and most other widgets actually i suggest you create a icon management class. With a getter method which returns the correct item depending on the current style set. This class needs to signal when the style changes. So the widgets can retrieve the icons again.

      Are we talking about a QStyle/QStyleSheetStyle which changes or is it simply a "state-change" which you referring to when talking about style change?

      --- 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
      0
      • ImunarI Offline
        ImunarI Offline
        Imunar
        wrote on last edited by
        #3

        @raven-worx
        at the moment the icon comes from a qrc file
        /light/close.svg alias: close.svg
        /dark/close.svg alias: close.svg

        In my main I start the application with
        *QApplication::setStyle("lightstylename") *and try to load my QProxyStyle
        which sets the QPalette and some specific Widget StyleSheets (Colors, Borders, Padding etc)

        then during run time the user may switch into night mode
        and activates
        QApplicaton::setStyle("darkstylename")
        and then I need my Icons with more contrast.

        raven-worxR 1 Reply Last reply
        0
        • ImunarI Imunar

          @raven-worx
          at the moment the icon comes from a qrc file
          /light/close.svg alias: close.svg
          /dark/close.svg alias: close.svg

          In my main I start the application with
          *QApplication::setStyle("lightstylename") *and try to load my QProxyStyle
          which sets the QPalette and some specific Widget StyleSheets (Colors, Borders, Padding etc)

          then during run time the user may switch into night mode
          and activates
          QApplicaton::setStyle("darkstylename")
          and then I need my Icons with more contrast.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @Imunar
          So then you can listen to a QEvent::StyleChange event. And retrieve the icons again.
          This event should be received by every widget. But you can also install an eventfilter on the qapplication if you like.

          --- 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
          • ImunarI Offline
            ImunarI Offline
            Imunar
            wrote on last edited by
            #5

            @raven-worx
            ahh I see.
            So if I keep the icon alias
            I could replace the old Icon with the new one
            on style change.

            btw. is there a reason why QIcon don't keep the QString if it's created by one?
            as QIcon::name() only works on themedIcons

            raven-worxR 1 Reply Last reply
            0
            • ImunarI Imunar

              @raven-worx
              ahh I see.
              So if I keep the icon alias
              I could replace the old Icon with the new one
              on style change.

              btw. is there a reason why QIcon don't keep the QString if it's created by one?
              as QIcon::name() only works on themedIcons

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @Imunar
              i was thinking of something like this:

              QIcon myIconManagerClass::getIcon( const QString & name )
              {
              return QIcon( QString("%1/%2").arg( isDarkStyle ? "dark" : "light" ).arg( name ) );  //update "isDarkStyle" when receiving QEvent::StyleChange accordingly
              }
              ...
              myIconManagerClass->getIcon( "icon.png" );
              

              --- 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
              2
              • ImunarI Offline
                ImunarI Offline
                Imunar
                wrote on last edited by
                #7

                thanks @raven-worx
                I've got the point and mark this one as solved

                thanks for your support!

                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