QT to center a window (or control)

Source: Internet
Author: User

The code is as follows:

[CPP]View Plaincopyprint?
  1. Xxx::xxx (qwidget *parent/ * = 0 */)
  2. {
  3. ..................
  4. //Note that resize must be placed in front of this code
  5. Resize (300, 300);
  6. int CX, CY;
  7. //When the parent is empty, the window is displayed in the center of the desktop
  8. if (NULL = = parent)
  9. {
  10. CX = (qapplication::d esktop ()->width ()-width ())/2;
  11. cy = (qapplication::d esktop ()->height ()-height ())/2;
  12. }
  13. //Otherwise, the control is displayed in the center of the parent part
  14. Else
  15. {
  16. CX = (Parent->width ()-width ())/2;
  17. cy = (parent->height ()-height ())/2;
  18. }
  19. Move (CX, CY);
  20. ....................
  21. }


This code is too often used, and then send up and share it with you, hehe.

http://blog.csdn.net/small_qch/article/details/6973956

QT to center a window (or control)

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.