Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



  • 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).


  • Lifetime Qt Champion

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



  • 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
    

  • Lifetime Qt Champion

    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.



  • @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>
    

  • Lifetime Qt Champion

    @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.


Log in to reply