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 rendering differently on Linux vs windows.
Qt 6.11 is out! See what's new in the release blog

SVG rendering differently on Linux vs windows.

Scheduled Pinned Locked Moved Unsolved General and Desktop
svglinux desktopiconqtreeviewstylesheet
10 Posts 4 Posters 470 Views 2 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.
  • J Offline
    J Offline
    Jammin44fm
    wrote last edited by Jammin44fm
    #1

    Hi All,

    Qt 6.5.3,
    win10/win11 vs
    Ubuntu 24.04.1 xcfe or wayland platform plugin, both exhibit same behavior.

    Recently I've ported a number of icons from PNG to SVG, and the new SVG icons are displaying in a smaller size on Linux relative to windows.
    I'm using the inbuilt iconengine functionality to load an SVG as a resource from an stylesheet.
    Specifically the images are used as the "has siblings open / closed" images within a QTreeView.

    My Stylesheet is

        QTreeView::branch:has-children:!has-siblings:closed,
        QTreeView::branch:closed:has-children:has-siblings { border-image: none; image: url(:/BrowserWidget/ClosedArrow.svg); }
        QTreeView::branch:open:has-children:!has-siblings,
        QTreeView::branch:open:has-children:has-siblings { border-image: none; image: url(:/BrowserWidget/OpenArrow.svg); }
    

    On windows this looks like:
    3c99702d-7369-4ae9-8d43-2f004422c835-image.png

    however on Linux it looks like:
    1317af4e-ca84-497a-acde-738069fa46ed-image.png

    Notice that the arrow is significantly smaller on the Linux version.
    They are both using identical SVG images, stylesheet, and drawing code.

    Has anyone seen anything like this before?
    I'd really like to avoid using different SVG images on each platform

    the source for the SVG itself is very simple,

    <svg width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path d="M8 5.00009L2 8.66009V1.34009L8 5.00009Z" fill="#CCCCCC"/>
    </svg>
    

    If I had to guess, I would say that the Linux version is showing the SVG at 1:1, but the windows version is doing some additional scaling to increase the visible size of the image used. Because the view box is 10x10, but the actual image drawn is less than that, and the window's screen shot shows the arrow as occupying close to a 10x10 box, But the linux arrow is much smaller.

    Because I am using the stylesheet and iconengine to handle the SVG loading, and not explicitly reading it with QtSvg,
    I dont have much control over how the image is handled.
    I've tried adding a height and width argument to the stylesheet, but that doesn't seem to have any effect?
    Perhaps this is the issue/Bug?
    I dont have a good understanding of what the width and height values do in the case of an SVG resource.

    I'd love some help and or explanation of what is going on?

    • James
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote last edited by
      #2

      Hi,

      Out of curiosity, what happens if your set the icon-size in your stylesheet ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jammin44fm
        wrote last edited by
        #3

        Thanks for the suggestion, but using the icon-size in my stylesheet doesn't have any effect.
        I'm working on reproducing the issue in simpler Qt only sample.
        Perhaps there is some other aspect of our styling that is causing the problem.
        But strange that things are OK on Mac and Windows, but I have this specific issue on Linux.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jammin44fm
          wrote last edited by
          #4

          I've created a very simple TreeView sample app that lets me modify the stylesheet directly within the code,
          but nothing i do seems to effect the size of the Arrow icons attached to the sibling with children items in the Treeview.

          the code...

          #include <QApplication>
          #include <QScreen>
          #include <QTreeView>
          #include <QStandardItemModel>
          #include <QHeaderView>
          
          
          int main(int argc, char *argv[]) {
              QApplication app(argc, argv);
          
              // 1. Create the Tree View and populate data
              QTreeView treeView;
              QStandardItemModel model(4, 2);
              model.setHeaderData(0, Qt::Horizontal, "Task Name");
              model.setHeaderData(1, Qt::Horizontal, "Status");
          
              // Fill dummy hierarchical data
              for (int i = 0; i < 3; ++i) {
                  QStandardItem *parentItem = new QStandardItem(QString("Project Phase %1").arg(i + 1));
                  QStandardItem *statusItem = new QStandardItem("In Progress");
                  model.setItem(i, 0, parentItem);
                  model.setItem(i, 1, statusItem);
          
                  for (int j = 0; j < 2; ++j) {
                      QStandardItem *childItem = new QStandardItem(QString("Sub-task %1.%2").arg(i + 1).arg(j + 1));
                      QStandardItem *childStatus = new QStandardItem("Pending");
                      parentItem->appendRow(QList<QStandardItem*>() << childItem << childStatus);
                  }
              }
          
              treeView.setModel(&model);
              treeView.expandAll();
          
              // Enable alternating backgrounds required by the stylesheet
              treeView.setAlternatingRowColors(true);
          
              // 2. Define and Apply the QSS Stylesheet
              QString treeStylesheet = R"(
                  /* Main view styling */
               QTreeView { background: #4d4d4d; selection-color: black; selection-background-color: #f9d20e; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; show-decoration-selected: 1; }
               QTreeView::item { height: 25px; padding-left: 7px; background-color: transparent; }
               QTreeView::branch:has-siblings:!adjoins-item { border: none; }
               QTreeView::branch:has-siblings:adjoins-item { border: none; }
               QTreeView::branch:!has-children:!has-siblings:adjoins-item { border: none; }
               QTreeView::branch:has-children:!has-siblings:closed,
               QTreeView::branch:closed:has-children:has-siblings { border-image: none; image: url(:/ClosedArrow.svg);      width: 5px; height: 5px; }
               QTreeView::branch:open:has-children:!has-siblings,
               QTreeView::branch:open:has-children:has-siblings { border-image: none; image: url(:/OpenArrow.svg);      width: 5px; height: 5px; }
               QTreeView QLineEdit { color: #000000; background: #ffffff }
               QTreeView QScrollBar:vertical { padding-left: 3px; background: black; width: 11px; margin: 0px; }
          
          
              )";
          
              treeView.setStyleSheet(treeStylesheet);
              treeView.resize(450, 300);
              treeView.show();
          
              return app.exec();
          }
          

          I've been swapping out the PNG's and SVG's - each result in a different size of the triangle that get rendered, but neither SVG or PNG are effected by the icon-size or, width and height properties?

          How am I supposed to get matched sizes?
          The SVG file is near exact copy of the PNG image, why am i getting such different results?
          and what is the correct way to control the icon size for this specific icon / image?

          Regards,

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote last edited by
            #5

            Do you also have somewhere a set of images to test ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • J Offline
              J Offline
              Jammin44fm
              wrote last edited by
              #6

              There are the PNG's...
              ClosedArrow.png OpenArrow.png

              Hmm it wont let me attach the SVG's

              But I'll paste the svg.
              Closed Arrow

              <path d="M8 5.00009L2 8.66009V1.34009L8 5.00009Z" fill="#CCCCCC"/>
              </svg>
              
              Open Arrow
              <svg width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg">
              <path d="M8.65997 2L4.99997 8L1.33997 2H8.65997Z" fill="#CCCCCC"/>
              </svg>
              

              Looking at the images side by side I can see they are slightly different,
              But in a way that is the opposite of how they are displayed ion the sample app!!

              The png versions have the triangle touching the sides of the image,
              However in the SVG's the triangles has some empty space around the triangle.
              But in the sample the png version the arrows looks smaller, and the svg looks bigger?

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SimonSchroeder
                wrote last edited by
                #7

                I know very little about SVG syntax. However, what I see is that there is a fill color set. Usually, shapes also have an outline/border/stroke. Maybe you can specify the stroke width as well (maybe as 0?). There might be different defaults on Windows and Linux about the outline. It's just a wild guess.

                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote last edited by
                  #8

                  The width and height properties is not supported for the image property. See also https://doc.qt.io/qt-6/stylesheet-reference.html#image why a png is rendered with a different sice than a svg.

                  I've filled a bug report about this and also created an initial patch
                  https://qt-project.atlassian.net/browse/QTBUG-147536

                  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
                  2
                  • J Offline
                    J Offline
                    Jammin44fm
                    wrote last edited by
                    #9

                    Ahh thanks for the additional info, and for the Bug link.
                    That would seem to explain the behavior I am seeing - on Linux anyway.

                    It seems that the only solution for the moment is to modify the SVG themselves :(

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      Jammin44fm
                      wrote last edited by
                      #10

                      I've tested the same code against Qt 6.9.3 and it doesn't seem to be an issue there.

                      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