Qt Settings window Center display and form size

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.