I tried this in my mainform constructor
This is probably the problem. You may not have valid geometry information at this time because the object is not visible.
When an object is first created, it is essentially positioned at (0,0) with the expected (width,height) , as such:
frame geometry at construction: QRect(0,0 639x479)
But after the show:
frame geometry rect: QRect(476,337 968x507)
Thus, you cannot yet rely on frameGeometry() .
EDIT : With that said, I suppose you can easily move it as you wish, but for completeness I will add a Patrice code that does not depend on information about the frame geometry:
QRect desktopRect = QApplication::desktop()->availableGeometry(this); QPoint center = desktopRect.center(); move(center.x() - width() * 0.5, center.y() - height() * 0.5);
Kaleb pederson
source share