Hello,
you ask too early for the window position (in the CTOR). Try overriding QMainWindow::moveEvent() and print the result of geometry() inside this function. You observe that moveEvent() gets called multiple times even without manually moving the window around.
Here is a code snippet:
{
std::cout << "moveEvent: ";
std::cout << "x = " << r.x() << ", y = " << r.y() << ", width = " << r.width() << ", height = " << r.height() << std::endl;
}
void MainWindow::moveEvent(QMoveEvent *e)
{
QMainWindow::moveEvent(e);
QRect r = geometry();
std::cout << "moveEvent: ";
std::cout << "x = " << r.x() << ", y = " << r.y() << ", width = " << r.width() << ", height = " << r.height() << std::endl;
}
To copy to clipboard, switch view to plain text mode
Running the application produces the following output:
CTOR: x = 0, y = 0, width = 400, height = 300
moveEvent: x = 0, y = 0, width = 400, height = 300
moveEvent: x = 808, y = 23, width = 400, height = 300
The line with CTOR shows the coordinates received when calling geometry in the contructor. Note that there are two calls to moveEvent().
You may also look at frameGeometry() and pos() methods. See http://doc.qt.io/qt-5.4/application-...indow-geometry for details.
Best regards
ars
Bookmarks