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. High DPI Screenshot of QtWidget Application
Forum Updated to NodeBB v4.3 + New Features

High DPI Screenshot of QtWidget Application

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 892 Views 1 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.
  • M Offline
    M Offline
    moritzh
    wrote on last edited by
    #1

    Hello,

    I want to make a high DPI screenshot of an Qt widgets application, while the app is running on a normal monitor without any DPI scaling. Therefore I'm currently using a QPixmap as rendertarget for the widget. I have made a minimal reproduction example:

    main.cpp:

    #include <QApplication>
    #include <QPushButton>
    #include <QVBoxLayout>
    
    int main(int argc, char *argv[])
    {
        QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    
        QApplication a(argc, argv);
    
        QVBoxLayout layout;
        QPushButton btn("Hello");
        layout.addWidget(&btn);
    
        QWidget w;
        w.setLayout(&layout);
        w.resize(200, 150);
        w.show();
    
        QPixmap pixmap(800, 600);
        pixmap.setDevicePixelRatio(4.0);
        w.render(&pixmap);
        pixmap.save("test.png");
    
        return a.exec();
    }
    
    

    qmake:

    QT += core gui widgets
    CONFIG += c++11
    SOURCES += main.cpp
    

    When I run this code, this is the result:
    test1.png
    The text is rendered fine with high resolution, but the border of the button is still rendered in low resolution.

    When I run this code with QT_SCALE_FACTOR=4 ./test the result looks like what i want:
    test2.png
    But the sideeffect is that the whole application is scaled by factor 4.

    Does anybody have an idea how to make a high resolution "screenshot", while the app is running in normal resolution?

    I use Qt 5.14.0 on Ubuntu 18.04.

    Regards
    Moritz

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      It's really not the same with high resolution as high DPI.
      You can pretend your normal monitor has many pixels but the actual Qt scaling
      is not in effect since the DPI is at a normal level.
      However, using QT_SCALE_FACTOR you enable that scaling so
      for a true High DPI shot, you need that and yes its only for whole app.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        moritzh
        wrote on last edited by
        #3

        I thought that pixmap.setDevicePixelRatio(); is for setting the DPI of the Pixmap. And as you see on the screenshot this works correctly for text and the general layout calculation is correct. Only the rendering of the border of the button is rendered with low DPI.
        When the resolution of the Pixmap is generally not meant to be used as High DPI, then I don't understand why it works for the text. So is this a bug in Qt that there is an inconsistency between rendering of text and button border, or this defined behaviour?

        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