@SimonSchroeder
Interesting, ill admit I don't full understand what your code is doing, I was more looking for a way to detect DPI changes without using a timer/movement based approach , only doing work when it needs doing, so now I do something like this
QObject::connect(qApp->primaryScreen(), &QScreen::logicalDotsPerInchChanged, [this](qreal screen_geometry) {
qDebug() << "logical DPI changed:" << QWidget::window()->screen()->devicePixelRatio();
// Such as when I change OS DPI settings , like you mention
});
QObject::connect(QWidget::window()->windowHandle(), &QWindow::screenChanged, [this](QScreen* screen) {
qDebug() << "Screen changed:" << QWidget::window()->screen()->devicePixelRatio();
// Such as when I drag over to a different monitor
});
I then call some handler if need be to tell it to use this new DPI which works perfectly. I'm only using this DPI to recalculate some orthogonal matrices and viewports
Edit: If I understand right, you are updating the ratio yourself based on the windows current screen and the primary screen? Won't that impact the pixel ratio (through OS settings) if you modify the primary screen but not the screen its currently on? Directly using QScreen::devicePixelRatio works for me and is clean, sounds like slightly different use cases :)