When I last did this (about a decade ago) I used QSettings, and had to check if the coordinates were valid in case the monitor configuration changed. If none were out of bounds (negative or > max) then the configuration was considered valid. If invalid, it positioned itself on the default monitor.
Please be careful though. I hate it when an app positions its title bar off screen then have to use alt-space,m,(arrow keys) to bring it back down. (I've been using that trick since the 90's when MS Office apps had a bug. (Changing monitor sizes) ) > Sent: Monday, August 03, 2015 at 12:41 PM > From: "Murphy, Sean" <smur...@walbro.com> > To: "interest@qt-project.org" <interest@qt-project.org> > Subject: [Interest] Seeking tips on restoring application geometry > > I'm trying to be helpful to my users and restore window geometry between > sessions, but I was looking for advice on how to go about that. My > application is an internal engineering tool, that is usually used on laptops > that routinely bounce between being used as a standalone laptop in a lab > setting (so using the laptop monitor only) and being connected to external > monitor(s) back at the user's desk. > > I've already found QWidget::saveGeometry() and QWidget::restoreGeometry(). So > my original attempt was to use saveGeometry() in my mainwindow's destructor, > and restoreGeometry() in the mainwindow's constructor. The downside to this > is that it's pretty common to have the user quit the application on the > bigger desktop, and then relaunch on the smaller desktop where the geometry > I'm attempting to restore doesn't exist. I know in > QWidget::restoreGeometry()'s documentation there's this: "If the restored > geometry is off-screen, it will be modified to be inside the available screen > geometry.", so at least I don't have to worry about the application not being > visible going from big desktop to small, but it doesn't really help when > going from small to big. > > I'm kind of leaning towards saving multiple geometries in my settings based > on the current desktop size, so that the user can set one geometry for the > laptop-only case, set a different geometry for the external monitor(s) case, > and have the application remember those settings independently. I'm just not > sure if I'm overlooking an obvious pitfall with this approach? > > Sean > _______________________________________________ > Interest mailing list > Interest@qt-project.org > http://lists.qt-project.org/mailman/listinfo/interest > _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest