QScreen, devicePixelRatio, and QGraphicsScene
-
I am developing an application that basically takes a screenshot (or grabs a selectable part of the screen) and allows to draw on top of it with different tools.
The goal is to be as visually unintrusive as possibly, creating the impression that one draws on top of the computer screen (it is used for teaching).
To this end, I use the combination of the following settings
setWindowState(Qt::WindowFullScreen | Qt::WindowMaximized); setWindowFlags(Qt::FramelessWindowHint);
and have a
MainWindow
that contains just aQGraphicsView
. I also set theQDrawingScene
's area to match the screen sizesetSceneRect(QGuiApplication::primaryScreen()->geometry());
and disable the scrollbars in the QGraphicsView:
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
This all works fine on one computer.
On another machine, that has the (AFAIK) exact same setup, I have two monitors connected and use them in a "side by side" configuration.
Here, the content of theQGraphicsScene
does no longer match the one of the underlying screen. Basically, I can scroll the scene using the mouse wheel. After some investigation, I found out that this is related todevicePixelRatio()
being different from 1.0.So my questions are:
- is there a way to force, for this particular application, a
devicePixelRatio
of 1.0? This would make everything simpler, especially since some operations like cropping the screenshot work in units of raw screen pixels. - if this is not possible, is there a simple and safe way to set the right
sceneRect
and somehow disable scrolling? Do I have to set a scale factor so that the Scene just "matches"? I fear that this could become tricky because when I multiplied the scene width by the pixel ratio I obtained fractional pixel values, so there seem to be roundoff issues. - I noticed that on the first computer, the screen still can be scrolled by a pixel or two. I read somewhere that even the "frameless" window has a border of 1 pixel around. If this is strictly 1 pixel, this would be quite easy to address, but I am not sure... In an ideal case, this frame could be entirely "disabled"... is this possible?
So far, I am under X.org (a Kubuntu 23.04 system), but wonder whether the problems outlined above are solved in the same way under Wayland?
- is there a way to force, for this particular application, a