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
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 700 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 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
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 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 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
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 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
          0
          • Christian EhrlicherC Christian Ehrlicher

            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 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>
            
            jsulmJ 1 Reply Last reply
            0
            • K Kite R

              @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>
              
              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on 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
              • J Offline
                J Offline
                JosepSubi
                wrote last edited by
                #7

                i've bypassed it using :
                QSize iconSize(16, 16);
                QPixmap img = QIcon::fromTheme("folder-alt").pixmap(iconSize).scaled(iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
                qDebug() << img;

                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