Qt-center window display

Source: Internet
Author: User

In QT,ProgramAfter running, the window is displayed in the center of the screen by default, but it is not displayed in the center of the XP system. You need to adjust it manually.

Like other online solutions, most people useCode

Move (desktop-> width ()-This-> width ()/2, (desktop-> height ()-This-> height ()/2 );

This code has two problems.

1. The width and height of the desktop contain the width and height of the taskbar, which may cause the window location to be less accurate. For example, the top and bottom values of the window may be much different.

2. the taskbar is left, top, and right.

 

The improved code is as follows:

W. move (qapp-> desktop ()-> availablegeometry (). width ()-w. width ()/2 + qapp-> desktop ()-> availablegeometry (). X (), (qapp-> desktop ()-> availablegeometry (). height ()-w. height ()/2 + qapp-> desktop ()-> availablegeometry (). Y ());

Availablegeometry is the rectangular area returned that does not contain the taskbar. This ensures that the center position is more accurate.

Add the XY coordinates of availablegeometry to ensure that the program can also appear in the correct position on the desktop that has adjusted the taskbar position, instead of overlapping the taskbar.

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.