Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-60026

Setting a widget's QGraphicsEffect causes it to not scale properly in HiDPI

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P3: Somewhat important P3: Somewhat important
    • 5.9
    • 5.6.1, 5.8.0
    • GUI: Painting
    • None
    • Linux Mint KDE 18.1, Antergos.
    • 8b62673d9f0cf8aea126b3cd2f52686f013d7fe1, 9595622e366fcbef6bcc3a2ee08597959e3e2bd2, db2de20c59137eab15fac9592c001a4d234c82d4 (qtbase/5.9, 19.4.17, 5.9)

      When setting a QGraphicsEffect of any kind on a widget, the effect is drawn in such a way that the widget's text/image no longer scales properly in HiDPI.

      For example, if you run a Qt application with QT_SCALE_FACTOR=2, and then set a QGraphicsColorizeEffect on a QLabel, that label will not look crisp when it is scaled. Instead it will be scaled, but will look jagged and pixelated. This also happens to icons that are set in the widget, and even to SVG images. If no QGraphicsEffect were set, then the text or image would scale properly and look crisp.

      Below is some sample code:

      HiDPI with QGraphicsEffect
      #include <QApplication>
      #include <QLabel>
      #include <QGraphicsColorizeEffect>
      #include <QMainWindow>
       
      int main(int argc, char **argv)
      {
          QApplication app(argc, argv);
      
          QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
          QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
      
          QLabel* helloLabel = new QLabel("Hello");
      
          QGraphicsColorizeEffect* effect = new QGraphicsColorizeEffect();
          effect->setColor(Qt::green);
      
          helloLabel->setGraphicsEffect(effect);
      
          QMainWindow* window = new QMainWindow();
          window->setCentralWidget(helloLabel);
       
          window->show();
          return app.exec();
      }
      

      If you run the above with the environment variable QT_SCALE_FACTOR set to 1 (or without that environment variable set at all), the text will be green and will look normal, as seen in the attached image "no_hidpi.png". If you run the above with QT_SCALE_FACTOR=2 to test for HiDPI displays, the text will be overly large and jagged. It will also be clipped. See the attached image "hidpi.png".

      Interestingly enough, if you use a drop shadow effect instead, the text or image in the widget will scale properly and look crisp, but the drop shadow will look jagged.

      However, other custom QGraphicsEffects show similar behavior to the QGraphicsColorizeEffect and do not look crisp when scaled.

        1. qtbug60026.zip
          2 kB
        2. qtbug60026.jpg
          qtbug60026.jpg
          146 kB
        3. no_hidpi.png
          no_hidpi.png
          13 kB
        4. hidpi.png
          hidpi.png
          12 kB
        For Gerrit Dashboard: QTBUG-60026
        # Subject Branch Project Status CR V

            kleint Friedemann Kleint
            wereturtle wereturtle
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes