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. HiDPI and SVG icon resolution
QtWS25 Last Chance

HiDPI and SVG icon resolution

Scheduled Pinned Locked Moved Solved General and Desktop
svgiconshidpiresolution
24 Posts 4 Posters 9.4k 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.
  • C Offline
    C Offline
    cle1109
    wrote on 31 Oct 2019, 08:11 last edited by
    #15

    @SimonSchroeder I think there is something wrong with the code because like in the first version, I get a more or less random icon with the second version as well. It looks like either the conversion icon = QIcon(pixmap) doesn't work or one of the preceding steps.

    S 1 Reply Last reply 4 Nov 2019, 07:50
    0
    • C cle1109
      31 Oct 2019, 08:11

      @SimonSchroeder I think there is something wrong with the code because like in the first version, I get a more or less random icon with the second version as well. It looks like either the conversion icon = QIcon(pixmap) doesn't work or one of the preceding steps.

      S Offline
      S Offline
      SimonSchroeder
      wrote on 4 Nov 2019, 07:50 last edited by
      #16

      @cle1109 You can try if it is one of the preceeding steps by calling pixmap.save(...) and have a look at the saved image.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cle1109
        wrote on 5 Nov 2019, 08:46 last edited by
        #17

        I did pixmap.save("pixmap.png") after the painter stuff and the resulting PNG doesn't look right. So either the painter doesn't paint correctly into the pixmap or the image is not read in correctly. Can I debug this further to find out what the problem is?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SimonSchroeder
          wrote on 6 Nov 2019, 10:36 last edited by
          #18

          To me, this means that the painter does not paint correctly. I'm out of ideas.

          Maybe, one last thing to check: I am not sure how a QPython project would be set up. For C++ I am using qmake. One thing I noticed is that in the end SVG icons are working. However, it would be more correct to add Qt's SVG module, i.e. I would add the line

          QT += svg
          

          to my qmake project file. Is there something similar for Python?

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cle1109
            wrote on 6 Nov 2019, 10:46 last edited by
            #19

            I don't think this is necessary in Python. It is sufficient to import the required packages. In the example, I don't explicitly require the PyQt5.QtSvg module, but I don't think this is a problem (the stuff I'm using should automatically use functions from that module if needed).

            I will rewrite my example in C++ to see if this is a problem specific to the Python bindings. That way, it will be easier to decide where to file the bug report (since this is working on Windows and Linux). I'll keep you posted.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              cle1109
              wrote on 6 Nov 2019, 14:16 last edited by
              #20

              I tried this example in C++ and the result is exactly the same. The SVG icon is rendered in a very low resolution.

              #include <QApplication>
              #include <QMainWindow>
              #include <QIcon>
              #include <QAction>
              #include <QToolBar>
              
              
              int main(int argc, char **argv)
              {
                  QApplication app(argc, argv);
                  QMainWindow window;
                  QIcon icon("waves-24px.svg");
                  QAction action(icon, "Test");
                  QToolBar *toolbar = new QToolBar(&window);
                  toolbar->addAction(&action);
                  window.addToolBar(toolbar);
                  window.show();
                  return app.exec();
              }
              
              1 Reply Last reply
              0
              • C Offline
                C Offline
                cle1109
                wrote on 6 Nov 2019, 15:06 last edited by
                #21

                Also, here's my main.pro file I used to build the app. It doesn't make a difference whether or not I include svg.

                TEMPLATE = app
                TARGET = main
                
                QT = core gui widgets
                
                SOURCES += main.cpp
                
                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SimonSchroeder
                  wrote on 7 Nov 2019, 07:32 last edited by
                  #22

                  You'll need to use the trick with the QPixmap and QPainter in C++ as well. In the background Python and C++ use the exact same functionality, so I wouldn't expect any other behavior without the workaround. (I have experienced this exact problem in C++ multiple times.)

                  For your main.pro you need to add the svg module also:

                  ...
                  QT = core gui widgets svg
                  ...
                  

                  This is what I actually meant with my last post.

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    cle1109
                    wrote on 7 Nov 2019, 10:35 last edited by
                    #23

                    You'll need to use the trick with the QPixmap and QPainter in C++ as well. In the background Python and C++ use the exact same functionality, so I wouldn't expect any other behavior without the workaround. (I have experienced this exact problem in C++ multiple times.)

                    I get exactly the same result as in Python (the icon is just a random pixel pattern).

                    Yes, I know what you meant, I tried adding svg but it didn't make any difference. Same for the workaround. So in conclusion, this seems to be a Qt bug on macOS which also affects PyQt5.

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      cle1109
                      wrote on 12 Nov 2019, 13:48 last edited by
                      #24

                      Turns out there is a simple solution:

                      app.setAttribute(Qt.AA_UseHighDpiPixmaps)
                      
                      1 Reply Last reply
                      6

                      24/24

                      12 Nov 2019, 13:48

                      • Login

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