Set Window Center Display
Method One: Add the following code to the constructor of the window (Qwidget class and derived class):
#include <QDesktopWidget>// ..... // =qapp->desktop (); You can also This->width ())/2this->height ())/2); // .......
When the window starts, it is centered on the screen when it is recompiled.
Method Two: Call the Move () function after calling the show () function, and J moves the window to the center of the screen.
#include <QDesktopWidget>int main (intChar *argv[]) { qapplication a (argc, ARGV); MainWindow W; W.show (); W.move ((qapplication::d esktop ()->width ()-w.width ())/2, (qapplication::d esktop ()->height ()- W.height ())/2); return a.exec ();}
Set Form size
In our programming, we sometimes want our program form to have a fixed size, which is the size we have when we edit it.
After my groping, and consult the material. A method was found. It's very simple, actually. In fact, the physical size of the form is first found. Then set the size of the fixed form, the core code is as follows:
int This,geometry (). width (); int This,geometry (). Height (); This // set form fixed size
Qt Settings window Center display and form size