Unsolved normalGeometry seems offset
-
The following snippet of code results in 'this' top-level widget moving/shifting on screen:
auto pt = this->normalGeometry().topLeft();
this->move(pt);This is creating a problem because I'm using normalGeometry to persist the position and size of the window on app exit without regards to it being minimized/maximized.
This seems like a bug because the geometry returned has the correct dimensions ... so what am I missing?BTW, I'm using QT 5.9 on Windows 10.
EDIT:
The work-around is to adjust the normalized position by the client area offset:
pt.ry() -= geometry().top() - y();
pt.rx() -= geometry().left() - x();As I mentioned above, the width and height is OK and does not need to be adjusted.
My opinion is that normalGeometry should adjust the position internally to be consistent with the size being that of the outer frame.Dan C.
-
Hi and welcome to devnet,
Shouldn't you be using the frameGeometry in order to move your widget since it's a top level window ?
-
@SGaist - that snippet of code was an attempt to simplify the issue. Here's the bigger picture in pseudo-code:
void MyAppWidget::closeEvent() { // save "restored" window geometry if it's maximized or minimized QSize sz = normalGeometry().size(); QPoint pt = normalGeometry().topLeft(); SaveSettings(sz, pt); } MyAppWidget::MyAppWidget() { QSize sz; QPoint pt; LoadSettings(sz, pt); resize(sz); // this is ok (width and height included the frame) move(pt); // this is not (top-left did NOT include the frame) }
The main idea is that the app should not fill the entire screen or resize to an icon sized window when it's launched. However, the code above puts the window in a noticeably offset position. I do have a work-around - I just think this is a bug or a bad inconsistency at best.
-
Do you have the same behaviour with a more recent version of Qt ?