How to obtain the correct widget size when the widget is not displayed by Qt, and how to obtain the widget size by qt

Source: Internet
Author: User

How to obtain the correct widget size when the widget is not displayed by Qt, and how to obtain the widget size by qt

This is because you want to display a dialog box in full screen mode, and there are several QLabel sizes in the dialog box. After determining the maximum available QLabel sizes, you can adjust the QLabel sizes Based on the content, therefore, you want to determine the maximum QLabel size in the constructor of the dialog box. However, both QWidget: updateGeometry () and QWidget: update () can only be used for visible controls, so how can we determine the final effect of the control layout when the control is invisible (within the constructor?

// Widgets are widgets that require a forced refresh layout, such as widgets such as the dialog box-> setAttribute (Qt: WA_DontShowOnScreen); widgets-> show (); widgets-> hide (); widget-> setAttribute (Qt: WA_DontShowOnScreen, false );

The preceding method can solve this problem because the process is not displayed on the interface and the execution speed is fast, so it has no impact on the user.

In addition, if the first-level sub-control of the dialog box is set to full screen, the size of the sub-control will be adjusted immediately, however, the second-level subcontrol and the subsequent control may not calculate the size immediately. For example, the subtab control of QTabWidget does not calculate the size immediately...

Note that the above method should be used with caution, which may cause abnormal distribution of Qt events. It is best to use it in a relatively definite process.

 

In fact, when the showEvent () in the dialog box is executed, the size of the control in the dialog box is correct, therefore, the override showEvent function in the dialog box is also an optional solution. However, because I need to adjust the QLabel size again, if this adjustment will cause the dialog box to be displayed on the screen, move the QLabel position again (it is also related to verticalSpacer used around the QLabel). In short, because you do not want to see the control Moving position after each dialog box is displayed, It is not used in showEvent () to modify the widget 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.