Using Screen with multiple monitors
-
My (desktop) application uses
Settings
so that the main window geometry is persisted. I am trying to fix an issue whereby my application can start up "off screen" if the user's hardware changed between runs. (And, because it is off screen, it is then difficult for the user to manipulate it to move back on screen.)What I would like to do is to detect in
Component.onCompleted
of myApplicationWindow
that the initial geometry is outside the available screen bounds, over all monitors, and adjust it if necessary. I thought I could useScreen
to provide the information for this but it seems likeScreen
only provides the height and width of one of my monitors. In fact it seems to refer to the one I have on the right. It seems that if I close my application while the main window is positioned in the left hand monitor, it saves the geometry with a negativex
value. I can see that this is restored correctly but the problem is that I need to be able to check this programmatically.Is there any way I can access information that allows me to tell whether a particular main window geometry will be visible on the available monitors?
-
I noticed this in
Screen
doc:Note that the Screen type is not valid at Component.onCompleted, because the Item or Window has not been displayed on a screen by this time.
so perhaps the approach I was planning would not work anyway, even if I could get the information out of
Screen
.I am wondering if instead I could make use of the information provided by
QGuiApplication::screens()
. I will look into this, but any tips would still be appreciated.