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

QWidget grab with HighDPI mode

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P3: Somewhat important P3: Somewhat important
    • 5.6.1
    • 5.6.0
    • None
    • Windows 7, Qt 5.6.0 MinGW
    • ccfe33dc670a1491d9e1daa2ae17f5fe30484276 (qtbase/5.6, 22.4.2016, 5.6.1)

      When enabled HighDPI support QWidget->grab function works wrong.

      Example:

      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
      
          QPushButton *btn = new QPushButton("TEST");
          connect(btn, &QPushButton::clicked, [=](bool checked ) {
              qDebug() << "Button size: " << btn->size();
      
              QPixmap defPix = btn->grab();
              qDebug() << "Default grab. Pixmap size: " << defPix.size();
              defPix.save("defpix.png");
      
              QPixmap dprPix = btn->grab(QRect(0,0, btn->width() * btn->devicePixelRatio(), btn->height() * btn->devicePixelRatio()));
              qDebug() << "Grab using dpr. Pixmap size: " << dprPix.size();
              dprPix.save("dprpix.png");
           });
          ui->verticalLayout->addWidget(btn);
      }
      

      Program outputs:

      Button size:  QSize(378, 17)
      Default grab. Pixmap size:  QSize(378, 17)
      Grab using dpr. Pixmap size:  QSize(756, 34)
      

      Real button size on screen is 756x34. But if use "Grab using dpr" we get wrong pixmap. See attachments.

        1. defpix.png
          defpix.png
          0.9 kB
        2. dprpix.png
          dprpix.png
          1 kB
        3. qtbug52137.zip
          2 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            kleint Friedemann Kleint
            keshav Konstantin Semenov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes