QCustomPlot Discussion and Comments

devicePixelRatio - High DPI SupportReturn to overview


I have been using QCP for a couple of years, and it works really well. A few days ago I have been looking at supporting high dpi monitors, and noticed that QCP2 beta has support for that. I gave it a try and it mostly works, but there are a few problems.

One problem is that the text at the axis ticks seems to be drawn at lower resolution and scaled up. Here is a screenshot that shows the issue with a pixelratio of 2:


The other problem is minor and easy to fix. It is that devicePixelRatio is not initialized correctly when it is not an integer and has to be set manually. Fixing that can be done by changing the line


to (notice the F in the end)


It would be great if you can fix the problem with the axis text or let me know if there is a workaround.

A tip for experimenting with the devicePixelRatio is putting this in the main function before the QApplication object is created:

qputenv("QT_SCALE_FACTOR", "1.5");

Keep up the good work!


I am confused as to how the Windows display scaling (Right click Desktop -> Display settings -> Change the size of text...) interacts with the devicePixelRatioF() in Qt. It seems no matter how I scale Windows, the Qt function returns 1.0.

If I set Windows scaling to 125%, I get 1.0 returned from devicePixelRatioF().

However, the Qt app I am testing is clearly drawn to a different scale than it appears with 100% Windows scaling.

If I use your last code bit above in my main() function, then devicePixelRatioF() returns the QT_SCALE_FACTOR as set by qputenv().

I don't use windows, but it sounds to me like all that its scaling does is changing the font size. What I have noticed is that changing the font size globally does not work too well in Qt unless care is taken when making the UI, so I always set the QApplication font size to 11. You can actually use the font size to scale the Qt application with a trick, but I don't know if it is recommended or good practise:

double scale = 1.0;
// Create a temporary QApplication object in its own scope so that it gets deleted
// afterwards. This is needed for getting the system font size.
    QApplication tmp(argc, argv);
    double ptFont = tmp.font().pointSizeF();
    if (ptFont < 0.0) {
        ptFont = tmp.font().pixelSize();
    if (ptFont > 11.0) {
        scale = ptFont / 11.0;

// Use the derived scale factor
qputenv("QT_SCALE_FACTOR", QString::number(scale).toLocal8Bit());

// Create the QApplication object to use
QApplication a(argc, argv);

// Ignore the OS font settings and do scaling with the method above.
QFont font = qApp->font();
if (font.pixelSize() > 0) {
} else {

// Create the main window and start the event loop

MainWindow w;

return a.exec();

Regarding the QCP devicePixelRatio, I have noticed that plotting gets a lot slower if it is not equal to 1. This really is a problem...