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

QPixmap looks ugly on laptop when DPI is set to 125%

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 6.9.0
    • None
    • Windows

    Description

      I'm trying to draw a png image (using QPixmap) in a QLabel with Qt6. I resize the pixmap to fit the QLabel size. It looks just fine when DPI is set to 100%. But on my laptop, where DPI is set to 125% (to make text bigger, this is the default recommended config on the laptop), the pixmap looks ugly (the lines are blured). See screenshot:

      The code is very simple:

      main.cpp:

       

      #include <QApplication>
      #include "mainwindow.h"
      int main( int argc, char* argv[] )
      {
          QApplication app(argc, argv);
          MainWindow wnd; 
          wnd.show();
          return app.exec();
      }
      

      mainwindow.h:

       

      #pragma once
      #include <QMainWindow>
      class MainWindow : public QMainWindow
      {
          Q_OBJECT
      public:
          MainWindow(QWidget* parent = NULL);
      };
      

       

      mainwindow.cpp:

       

      #include "mainwindow.h"
      #include <QVBoxLayout>
      #include <QHBoxLayout>
      #include <QPushButton>
      #include <QApplication>
      #include <QLabel>
      MainWindow::MainWindow( QWidget* parent ) : QMainWindow(parent)
      {
          QWidget* centralWidget = new QWidget(this);
          centralWidget->setLayout(new QVBoxLayout(centralWidget));
          QPushButton* button = new QPushButton(centralWidget);
          button->setIcon(QIcon(":/qtbug_pixmapscale/image.png"));
          QWidget* labelsWidget = new QWidget(centralWidget);
          labelsWidget->setLayout(new QHBoxLayout(labelsWidget));
          QLabel* titleLabel = new QLabel(centralWidget);
          titleLabel->setText("This is ugly:");
          QLabel* iconLabel = new QLabel(centralWidget);
          int maxHeight = titleLabel->sizeHint().height() + 10;
          iconLabel->setMaximumSize( QSize(maxHeight,maxHeight) );
          iconLabel->setPixmap(QPixmap(":/qtbug_pixmapscale/image.png").scaled(iconLabel->maximumSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
          
          labelsWidget->layout()->addWidget(titleLabel);
          labelsWidget->layout()->addWidget(iconLabel);
          centralWidget->layout()->addWidget(button);
          centralWidget->layout()->addWidget(labelsWidget);
          setCentralWidget(centralWidget);
      }
      

      Note:

      using `setDevicePixelRatio` is a good workaround:

      auto pixmap = QPixmap(":/qtbug_pixmapscale/image.png").scaled(iconLabel->maximumSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
      pixmap.setDevicePixelRatio(qApp->primaryScreen()->devicePixelRatio());
      iconLabel->setPixmap(pixmap);

      But it would be much better if it could be done automatically by QtPixmap class itself. One should not have to do this for every QPixmap it wants to show. Note that QIcon apparently handles this correctly.

      Attachments

        1. image.png
          19 kB
          Jean Porcherot
        2. screenshot.png
          5 kB
          Jean Porcherot
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            jpo38 Jean Porcherot
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes