Skip to content

Commit 4322a60

Browse files
committed
比例分配
1 parent 929d8d4 commit 4322a60

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

Diff for: QVBoxLayout/Data/VerticalLayoutStretch.ui

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>VerticalLayoutStretch</class>
4+
<widget class="QWidget" name="VerticalLayoutStretch">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>400</width>
10+
<height>300</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Form</string>
15+
</property>
16+
<property name="styleSheet">
17+
<string notr="true">#label {
18+
background: #5aaadb;
19+
}
20+
#label_2 {
21+
background: #85c440;
22+
}
23+
#label_3 {
24+
background: #f2b63c;
25+
}</string>
26+
</property>
27+
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,2,3">
28+
<item>
29+
<widget class="QLabel" name="label">
30+
<property name="text">
31+
<string>通过设置Stretch设置每部分的占比(1,2,3) 1/6</string>
32+
</property>
33+
<property name="alignment">
34+
<set>Qt::AlignCenter</set>
35+
</property>
36+
</widget>
37+
</item>
38+
<item>
39+
<widget class="QLabel" name="label_2">
40+
<property name="text">
41+
<string>2/6</string>
42+
</property>
43+
<property name="alignment">
44+
<set>Qt::AlignCenter</set>
45+
</property>
46+
</widget>
47+
</item>
48+
<item>
49+
<widget class="QLabel" name="label_3">
50+
<property name="text">
51+
<string>3/6</string>
52+
</property>
53+
<property name="alignment">
54+
<set>Qt::AlignCenter</set>
55+
</property>
56+
</widget>
57+
</item>
58+
</layout>
59+
</widget>
60+
<resources/>
61+
<connections/>
62+
</ui>

Diff for: QVBoxLayout/README.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- 目录
44
- [垂直布局](#1垂直布局)
55
- [边距和间隔](#2边距和间隔)
6+
- [比例分配](#3比例分配)
67

78
## 1、垂直布局
89
[查看 BaseVerticalLayout.ui](Data/BaseVerticalLayout.ui)
@@ -15,4 +16,17 @@
1516
1. 通过`setContentsMargins(20, 20, -1, -1)`设置左上右下的边距,-1表示默认值
1617
2. 通过`setSpacing``subControlRect`设置控件之间的间隔
1718

18-
![VerticalLayoutMargin](ScreenShot/VerticalLayoutMargin.png)
19+
![VerticalLayoutMargin](ScreenShot/VerticalLayoutMargin.png)
20+
21+
## 3、比例分配
22+
[查看 VerticalLayoutStretch.ui](Data/VerticalLayoutStretch.ui)
23+
24+
通过`setStretch`设置各个部分的占比 分别为:1/6 2/6 3/6
25+
26+
```python
27+
self.verticalLayout.setStretch(0, 1)
28+
self.verticalLayout.setStretch(1, 2)
29+
self.verticalLayout.setStretch(2, 3)
30+
```
31+
32+
![VerticalLayoutStretch](ScreenShot/VerticalLayoutStretch.png)

Diff for: QVBoxLayout/ScreenShot/VerticalLayoutStretch.png

23 KB
Loading

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ https://pyqt.site 论坛是专门针对PyQt5学习和提升开设的网站,分
2323
- [QVBoxLayout](QVBoxLayout)
2424
- [垂直布局](QVBoxLayout#1垂直布局)
2525
- [边距和间隔](QVBoxLayout#2边距和间隔)
26+
- [比例分配](QVBoxLayout#3比例分配)
2627
- [QHBoxLayout](QHBoxLayout)
2728
- [QGridLayout](QGridLayout)
2829
- [腾讯视频热播列表](QGridLayout/HotPlaylist.py)

0 commit comments

Comments
 (0)