Restore a NOT VALID Dialog Position Correct
-
Hallo,
I am not using the Qt Designer. I am coding the dialogs in Qt/c++ myself.
So far I save and restore the size and position of dialogs and it working fine.
I restore them just by lines like this:
resize(TSettings->viewTeachersDialog_size);
move(TSettings->viewTeachersDialog_pos);It is working fine as long as the display is not changed. But if someone saved the dialog on his second screen, close the application, unplug the second screen and restart the application, then the dialog is restored out of screen (of course). This sadly happen to laptop users that sometimes use a second screen at work.
So i wonder how to avoid this best.
By reading the screen resolution and check if the "move(pos)" is smaller then the resolution?
But what should i read best? QScreen size or QScreen virtualSize or ...?
Or is there something like a "valid" check if the dialog is on screen?And what is the best new value? At 0,0 might be the task bar. So better place it in the center?
Any advice for me?
Thank you
-
Hallo,
I am not using the Qt Designer. I am coding the dialogs in Qt/c++ myself.
So far I save and restore the size and position of dialogs and it working fine.
I restore them just by lines like this:
resize(TSettings->viewTeachersDialog_size);
move(TSettings->viewTeachersDialog_pos);It is working fine as long as the display is not changed. But if someone saved the dialog on his second screen, close the application, unplug the second screen and restart the application, then the dialog is restored out of screen (of course). This sadly happen to laptop users that sometimes use a second screen at work.
So i wonder how to avoid this best.
By reading the screen resolution and check if the "move(pos)" is smaller then the resolution?
But what should i read best? QScreen size or QScreen virtualSize or ...?
Or is there something like a "valid" check if the dialog is on screen?And what is the best new value? At 0,0 might be the task bar. So better place it in the center?
Any advice for me?
Thank you
Hi,
You could save the screen as well and if there's a mismatch on load, show the dialog on the default screen.
-
Hi,
You could save the screen as well and if there's a mismatch on load, show the dialog on the default screen.
-
@SGaist hmm.... If there is a mismatch, then just don't move at all and keep the default value by Qt?
Yes, that sounds clever. I will try.
Thank you -
@mpergand no. I saved it like this:
TSettings->viewTeachersDialog_size=size();
TSettings->viewTeachersDialog_pos=pos();saveGeometry and restoreGeometry haven't got that bug? I will try. Thank you for suggesting.
@Volker75 Hallo,
hmm.... I used saveGeometry/restoreGeometry and it worked first fine.
I used a laptop with a second screen. Placed the Qt dialog on the second screen and closed it. Unplugged the second screen and started my software again. Qt noticed the problem and opens the window on the other screen. That is fine.But then i done the same with my tower PC, since it has two screens installed. First it worked find, but then, as i unplugged screen 1 (instead of screen 2), then it doesn't restore on the enabled screen.
hmm... Not sure if it is worth to write an official bug report about this. But it might be maybe a problem also for users. -
The thing is that without more details between your two machines it's hard to consider what might be going on.
It can be OS dependent, desktop environment dependent, Qt version dependent, etc.
One thing you can do in your code is to check whether the widget ends up in an existing screen and adjust if not.
-
The thing is that without more details between your two machines it's hard to consider what might be going on.
It can be OS dependent, desktop environment dependent, Qt version dependent, etc.
One thing you can do in your code is to check whether the widget ends up in an existing screen and adjust if not.