简体   繁体   中英

qt set widget width according to layout'width

I have three instances of QWidget , WidgetMain and WidgetMerchandise and WidgetCentral . WidgetMain has BorderLayout , implemented in Border Layout Example . Now, WidgetMerchandise is on the west side of layout, WidgetCentral is set on Central side of layout.but I would like WidgetMerchandise to have width to 1/4 width of WidgetCentral . Do I have to reimplement sizeHint() and minimumSizeHit() or should I achieve this task using qt size policies?

The widget sizes within the same layout are controlled by stretch factors . You can call setStretch method of the layout, or your can directly set these factors in the designer mode:

在此处输入图片说明

The above picture shows the example of 3 widgets in one layout, and the default layoutStrech is 0,0,0 (it has the same effect as 1,1,1 ). You may change it to 1,4,1 for example, so the left most widget will be 1/4 width of the second (central) widget. This is the case when horizontal layout is used, where the stretch factor determines the width. Otherwise, if vertical layout is used, the stretch factor represents the ratio of heights.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM