How to set Qt window screen center display and size
- 2020-05-12 02:58:31
- OfStack
How to set the center display and size of Qt
Set the window to center
Method 1: add the following code to the constructor of the window (QWidget class and derived class) :
#include <QDesktopWidget>
//.......
QDesktopWidget* desktop = QApplication::desktop(); // =qApp->desktop(); Can also be
move((desktop->width() - this->width())/2, (desktop->height() - this->height())/2);
//.......
Method 2: call move() after calling show(), which moves the window to the center of the screen.
move ((QApplication::desktop()->width() - w.width())/2,
(QApplication::desktop()->height() - w.height())/2);
Set the size of the case used
resize ( int width int height ) ;
Thank you for reading, I hope to help you, thank you for your support of this site!