Skip to content

Commit 0c8e7d3

Browse files
committed
QHBoxLayout
1 parent 4322a60 commit 0c8e7d3

9 files changed

+196
-1
lines changed
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>BaseHorizontalLayout</class>
4+
<widget class="QWidget" name="BaseHorizontalLayout">
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+
<layout class="QHBoxLayout" name="horizontalLayout">
17+
<item>
18+
<widget class="QLabel" name="label">
19+
<property name="text">
20+
<string>通过 右键 -&gt; 布局 -&gt; 水平布局</string>
21+
</property>
22+
<property name="alignment">
23+
<set>Qt::AlignCenter</set>
24+
</property>
25+
</widget>
26+
</item>
27+
<item>
28+
<widget class="QPushButton" name="pushButton">
29+
<property name="text">
30+
<string>右侧按钮</string>
31+
</property>
32+
</widget>
33+
</item>
34+
</layout>
35+
</widget>
36+
<resources/>
37+
<connections/>
38+
</ui>
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>HorizontalLayoutMargin</class>
4+
<widget class="QWidget" name="HorizontalLayoutMargin">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>457</width>
10+
<height>216</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Form</string>
15+
</property>
16+
<property name="styleSheet">
17+
<string notr="true">#VerticalLayoutMargin {
18+
background: #5aaadb;
19+
}
20+
#label {
21+
background: #85c440;
22+
}</string>
23+
</property>
24+
<layout class="QHBoxLayout" name="horizontalLayout">
25+
<property name="spacing">
26+
<number>20</number>
27+
</property>
28+
<property name="rightMargin">
29+
<number>20</number>
30+
</property>
31+
<item>
32+
<widget class="QLabel" name="label">
33+
<property name="text">
34+
<string>通过设置Margin和Spacing设置边距
35+
以及两个控件之间的间隔距离</string>
36+
</property>
37+
<property name="alignment">
38+
<set>Qt::AlignCenter</set>
39+
</property>
40+
</widget>
41+
</item>
42+
<item>
43+
<widget class="QPushButton" name="pushButton_2">
44+
<property name="text">
45+
<string>Spcasing 为 20</string>
46+
</property>
47+
</widget>
48+
</item>
49+
<item>
50+
<widget class="QPushButton" name="pushButton">
51+
<property name="text">
52+
<string>Spcasing 为 20</string>
53+
</property>
54+
</widget>
55+
</item>
56+
</layout>
57+
</widget>
58+
<resources/>
59+
<connections/>
60+
</ui>
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>HorizontalLayoutStretch</class>
4+
<widget class="QWidget" name="HorizontalLayoutStretch">
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="QHBoxLayout" name="horizontalLayout" stretch="1,2,3">
28+
<item>
29+
<widget class="QLabel" name="label">
30+
<property name="text">
31+
<string>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>

QHBoxLayout/README.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# QHBoxLayout
2+
3+
- 目录
4+
- [水平布局](#1水平布局)
5+
- [边距和间隔](#2边距和间隔)
6+
- [比例分配](#3比例分配)
7+
8+
## 1、水平布局
9+
[查看 BaseHorizontalLayout.ui](Data/BaseHorizontalLayout.ui)
10+
11+
![BaseHorizontalLayout](ScreenShot/BaseHorizontalLayout.png)
12+
13+
## 2、边距和间隔
14+
[查看 HorizontalLayoutMargin.ui](Data/HorizontalLayoutMargin.ui)
15+
16+
1. 通过`setContentsMargins(-1, -1, 20, -1)`设置左上右下的边距,-1表示默认值
17+
2. 通过`setSpacing`设置控件之间的间隔
18+
19+
![HorizontalLayoutMargin](ScreenShot/HorizontalLayoutMargin.png)
20+
21+
## 3、比例分配
22+
[查看 HorizontalLayoutStretch.ui](Data/HorizontalLayoutStretch.ui)
23+
24+
通过`setStretch`设置各个部分的占比 分别为:1/6 2/6 3/6
25+
26+
```python
27+
self.horizontalLayout.setStretch(0, 1)
28+
self.horizontalLayout.setStretch(1, 2)
29+
self.horizontalLayout.setStretch(2, 3)
30+
```
31+
32+
![HorizontalLayoutStretch](ScreenShot/HorizontalLayoutStretch.png)
4.02 KB
Loading
Loading
Loading

QVBoxLayout/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
[查看 VerticalLayoutMargin.ui](Data/VerticalLayoutMargin.ui)
1515

1616
1. 通过`setContentsMargins(20, 20, -1, -1)`设置左上右下的边距,-1表示默认值
17-
2. 通过`setSpacing``subControlRect`设置控件之间的间隔
17+
2. 通过`setSpacing`设置控件之间的间隔
1818

1919
![VerticalLayoutMargin](ScreenShot/VerticalLayoutMargin.png)
2020

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ https://pyqt.site 论坛是专门针对PyQt5学习和提升开设的网站,分
2525
- [边距和间隔](QVBoxLayout#2边距和间隔)
2626
- [比例分配](QVBoxLayout#3比例分配)
2727
- [QHBoxLayout](QHBoxLayout)
28+
- [水平布局](QHBoxLayout#1水平布局)
29+
- [边距和间隔](QHBoxLayout#2边距和间隔)
30+
- [比例分配](QHBoxLayout#3比例分配)
2831
- [QGridLayout](QGridLayout)
2932
- [腾讯视频热播列表](QGridLayout/HotPlaylist.py)
3033
- [QFormLayout](QFormLayout)

0 commit comments

Comments
 (0)