Skip to content

Instantly share code, notes, and snippets.

@lslezak
Last active July 4, 2016 18:02
Show Gist options
  • Save lslezak/74966eedd88c700d5524c8c82e667236 to your computer and use it in GitHub Desktop.
Save lslezak/74966eedd88c700d5524c8c82e667236 to your computer and use it in GitHub Desktop.
Print the QGuiApplication::devicePixelRatio() value
// This simple utility prints the device pixel ratio reported by Qt library
// How to compile:
// - save into "qt_pixel_ratio" directory
// (the directory name determines the binary name, see later)
// - run "qmake-qt5 -project"
// - run "qmake-qt5"
// - run "make"
// Then you can run the "./qt_pixel_ratio" binary.
// (Use the name of the parent directory if you used another directory name
// in the first step.)
#include <QGuiApplication>
#include <QScreen>
#include <iostream>
int main(int argc, char *argv[])
{
QGuiApplication a(argc, argv);
std::cout << "Pixel Ratio: " << a.devicePixelRatio() << std::endl;
std::cout << "DPI(x): " << QGuiApplication::primaryScreen()->physicalDotsPerInchX() << std::endl;
std::cout << "DPI(y): " << QGuiApplication::primaryScreen()->physicalDotsPerInchY() << std::endl;
std::cout << "DPI(avg): " << QGuiApplication::primaryScreen()->physicalDotsPerInch() << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment