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::pixmap() returns image double the size requested
QtWS25 Last Chance

QIcon::pixmap() returns image double the size requested

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 569 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.
  • K Offline
    K Offline
    Kite R
    wrote on 23 Mar 2021, 02:31 last edited by Kite R
    #1

    I'm doing this to get images from an icon theme:

    QSize iconSize(16, 16);
    QIcon themeIcon = QIcon::fromTheme("name");
    
    QIcon icon;
    icon.addPixmap(themeIcon.pixmap(iconSize));
    
    return icon;
    
    qDebug() << themeIcon.pixmap(iconSize); // size is 32x32
    qDebug() << icon.pixmap(iconSize);      // size is 16x16
    

    The SVG file is 16x16, debug confirms iconSize is 16x16, but debug says the pixmap from the icon is 32x32, and at Hdpi (2x) 64x64.

    Why is this happening?

    When using QSvgRenderer I get the results I assumed I should be getting... 16x16 (1x) and 32x32 (2x).

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 23 Mar 2021, 05:48 last edited by
      #2

      Can you please show some code which is working instead just some lines which don't make any sense?

      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
      1
      • K Offline
        K Offline
        Kite R
        wrote on 23 Mar 2021, 09:53 last edited by Kite R
        #3

        Load one of the project examples in Qt Creator and with an icon theme, just get the pixmap from it, the size is double what I give.

        QSize iconSize(16, 16);
        QIcon themeIcon = QIcon::fromTheme("name");
        
        // Adding pixmap from theme icon to new icon
        QIcon icon;
        icon.addPixmap(themeIcon.pixmap(iconSize));
        
        return icon;
        
        // What I see in debug
        qDebug() << themeIcon.pixmap(iconSize); // size is 32x32
        qDebug() << icon.pixmap(iconSize);      // size is 16x16
        
        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 23 Mar 2021, 10:07 last edited by
          #4

          I still don't see where you call what. Please provide some code which is actually compilable so we can see what you're trying to do.

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

          K 1 Reply Last reply 23 Mar 2021, 10:46
          0
          • C Christian Ehrlicher
            23 Mar 2021, 10:07

            I still don't see where you call what. Please provide some code which is actually compilable so we can see what you're trying to do.

            K Offline
            K Offline
            Kite R
            wrote on 23 Mar 2021, 10:46 last edited by Kite R
            #5

            @Christian-Ehrlicher Then please download this project: https://github.com/DougBeney/Qt5-Icon-Themes-Example.

            Add these lines to main.cpp:

            QSize iconSize(16, 16);
            QPixmap img = QIcon::fromTheme("folder-alt").pixmap(iconSize);
            qDebug() << img;
            

            And this to qrc:

            <file>icons/zafiro/places/16/folder-alt.svg</file>
            
            J 1 Reply Last reply 23 Mar 2021, 14:54
            0
            • K Kite R
              23 Mar 2021, 10:46

              @Christian-Ehrlicher Then please download this project: https://github.com/DougBeney/Qt5-Icon-Themes-Example.

              Add these lines to main.cpp:

              QSize iconSize(16, 16);
              QPixmap img = QIcon::fromTheme("folder-alt").pixmap(iconSize);
              qDebug() << img;
              

              And this to qrc:

              <file>icons/zafiro/places/16/folder-alt.svg</file>
              
              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 23 Mar 2021, 14:54 last edited by
              #6

              @Kite-R As you're asking for help you should provide a simple and small example showing the behavior instead of asking others to download something, change this and that.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              6/6

              23 Mar 2021, 14:54

              • Login

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