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. SVG icons are stretched (not drawn pixel-perfect) with display scaling enabled
Qt 6.11 is out! See what's new in the release blog

SVG icons are stretched (not drawn pixel-perfect) with display scaling enabled

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 502 Views 1 Watching
  • 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.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by Violet Giraffe
    #1

    I'm simply setting a QAction icon from SVG file, and I emulate display scaling with setting env var QT_SCALE_FACTOR to 2.0.
    The icon looks like this, obviously rendered at 1x and then stretched. How can I work around this? Why does Qt do this in the first place with HiDpi support enabled?
    Tested with Qt 5.15.2.

    3dc3768e-9597-455d-a6e9-a20170044992-image.png

    Here's the complete repro code:

    int main(int argc, char *argv[]) {
    	qputenv("QT_SCALE_FACTOR", "2.0");
    	QApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
            QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
    	QApplication a(argc, argv);
    	a.setStyleSheet("*{background: #191919;	color: #DDDDDD;}");
    	QMainWindow w;
    	QToolBar* tb = new QToolBar;
    	w.addToolBar(tb);
    
    	QPixmap icon("help.svg");
    	icon.setDevicePixelRatio(2.0); // This appears to change nothing
    	tb->addAction(new QAction(icon, "text"));
    	w.show();
    	return a.exec();
    }
    

    Here's the sample project - an SVG icon and the code above. Since I can't attach a ZIP directly, here's a link to cloud storage. Turn off shadow build for the icon to load successfully.

    V 1 Reply Last reply
    0
    • V Violet Giraffe

      I'm simply setting a QAction icon from SVG file, and I emulate display scaling with setting env var QT_SCALE_FACTOR to 2.0.
      The icon looks like this, obviously rendered at 1x and then stretched. How can I work around this? Why does Qt do this in the first place with HiDpi support enabled?
      Tested with Qt 5.15.2.

      3dc3768e-9597-455d-a6e9-a20170044992-image.png

      Here's the complete repro code:

      int main(int argc, char *argv[]) {
      	qputenv("QT_SCALE_FACTOR", "2.0");
      	QApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
              QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
      	QApplication a(argc, argv);
      	a.setStyleSheet("*{background: #191919;	color: #DDDDDD;}");
      	QMainWindow w;
      	QToolBar* tb = new QToolBar;
      	w.addToolBar(tb);
      
      	QPixmap icon("help.svg");
      	icon.setDevicePixelRatio(2.0); // This appears to change nothing
      	tb->addAction(new QAction(icon, "text"));
      	w.show();
      	return a.exec();
      }
      

      Here's the sample project - an SVG icon and the code above. Since I can't attach a ZIP directly, here's a link to cloud storage. Turn off shadow build for the icon to load successfully.

      V Offline
      V Offline
      Violet Giraffe
      wrote on last edited by
      #2

      Turns out that creating icons via QPixmap is an anti-pattern. It is drawn correctly if constructing QIcon directly: QIcon icon("icon.svg");

      1 Reply Last reply
      1
      • V Violet Giraffe has marked this topic as solved on

      • Login

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