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. High DPI and Icons
Forum Update on Monday, May 27th 2025

High DPI and Icons

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 518 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by Perdrix
    #1

    I've got some Icons that I have created as 32x16 and 64x32 with intention of supporting High-DPI:

    They are currently in files with names like

    DarkColour-16.png and DarkColour-32.png

    I think it's possible to create a QIcon object that would automatically choose the right file?

    I want in my code to have e.g.

    static inline const std::vector<QIcon>  icons {
                QIcon("qrc:///stacking/DarkColour-16.png"),
                    etc...
            }
    

    and have it pick up the higher res file "automagically".

    Is that done with special (maybe different naming conventions)?

    Christian EhrlicherC D 2 Replies Last reply
    0
    • PerdrixP Perdrix

      I've got some Icons that I have created as 32x16 and 64x32 with intention of supporting High-DPI:

      They are currently in files with names like

      DarkColour-16.png and DarkColour-32.png

      I think it's possible to create a QIcon object that would automatically choose the right file?

      I want in my code to have e.g.

      static inline const std::vector<QIcon>  icons {
                  QIcon("qrc:///stacking/DarkColour-16.png"),
                      etc...
              }
      

      and have it pick up the higher res file "automagically".

      Is that done with special (maybe different naming conventions)?

      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Perdrix said in High DPI and Icons:

      and have it pick up the higher res file "automagically".

      See QIcon::addFile()

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • PerdrixP Perdrix

        I've got some Icons that I have created as 32x16 and 64x32 with intention of supporting High-DPI:

        They are currently in files with names like

        DarkColour-16.png and DarkColour-32.png

        I think it's possible to create a QIcon object that would automatically choose the right file?

        I want in my code to have e.g.

        static inline const std::vector<QIcon>  icons {
                    QIcon("qrc:///stacking/DarkColour-16.png"),
                        etc...
                }
        

        and have it pick up the higher res file "automagically".

        Is that done with special (maybe different naming conventions)?

        D Offline
        D Offline
        DerReisende
        wrote on last edited by
        #3

        @Perdrix you should name your files DarkColour.png and DarkColour@2x.png for the high-dpi version.

        1 Reply Last reply
        0
        • PerdrixP Offline
          PerdrixP Offline
          Perdrix
          wrote on last edited by
          #4

          So for clarity, if I have the resources set up like this:

          d074a6fa-6a3f-416e-a9d4-e707a0091041-image.png

          static inline const std::vector<QIcon>  icons {
                      QIcon("qrc:///stacking/DarkColour.png"),  // 32 wide 16 high
                      
                                          etc...
                  }
          

          and I then set the display Icon for the row of the TableModel to icons[0], it will automatically load use the x2 version of the icon as it builds the vector? That seems to be what the addFile documentation suggests?

          Is that right?

          Thanks David

          Christian EhrlicherC 1 Reply Last reply
          0
          • PerdrixP Offline
            PerdrixP Offline
            Perdrix
            wrote on last edited by
            #5

            bump-a-t-bump

            1 Reply Last reply
            0
            • PerdrixP Perdrix

              So for clarity, if I have the resources set up like this:

              d074a6fa-6a3f-416e-a9d4-e707a0091041-image.png

              static inline const std::vector<QIcon>  icons {
                          QIcon("qrc:///stacking/DarkColour.png"),  // 32 wide 16 high
                          
                                              etc...
                      }
              

              and I then set the display Icon for the row of the TableModel to icons[0], it will automatically load use the x2 version of the icon as it builds the vector? That seems to be what the addFile documentation suggests?

              Is that right?

              Thanks David

              Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Perdrix said in High DPI and Icons:

              Is that right?

              If you don't trust the documentation simply try it out.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              0
              • PerdrixP Offline
                PerdrixP Offline
                Perdrix
                wrote on last edited by
                #7

                I'm not testing the documentation, I'm testing my understanding of what you told me...

                I'm in the middle of a 20k + line change to some code that uses this ...

                D.

                Christian EhrlicherC 1 Reply Last reply
                0
                • PerdrixP Perdrix

                  I'm not testing the documentation, I'm testing my understanding of what you told me...

                  I'm in the middle of a 20k + line change to some code that uses this ...

                  D.

                  Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Perdrix said in High DPI and Icons:

                  I'm in the middle of a 20k + line change to some code that uses this ...

                  A small example with ~20loc would have told your understanding is correct or not.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  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