This may look crazy, but it works. Consider this code in the constructor of the form:
newX -= this->width () / 2;
this->setGeometry (newX, 0, this->width (), this->height ());
int newX = QApplication::desktop ()->width () / 2;
newX -= this->width () / 2;
this->setGeometry (newX, 0, this->width (), this->height ());
To copy to clipboard, switch view to plain text mode
In Line 1: QApplication::desktop ()->width () gets the maximum width of the current monitor where the app is
Do not forget to #include <QDesktopWidget> and #include <QApplication> .
Bookmarks