Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
k54kdk
PyQt Fluent Widgets
提交
cb4d6803
P
PyQt Fluent Widgets
项目概览
k54kdk
/
PyQt Fluent Widgets
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PyQt Fluent Widgets
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
cb4d6803
编写于
2月 13, 2022
作者:
之一Yo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加流式布局
上级
d8ef5a22
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
151 addition
and
0 deletion
+151
-0
README.md
README.md
+13
-0
screenshot/flow_layout.gif
screenshot/flow_layout.gif
+0
-0
widgets/flow_layout/demo.py
widgets/flow_layout/demo.py
+32
-0
widgets/flow_layout/flow_layout.py
widgets/flow_layout/flow_layout.py
+106
-0
未找到文件。
README.md
浏览文件 @
cb4d6803
...
@@ -124,6 +124,19 @@ A collection of commonly used widgets.
...
@@ -124,6 +124,19 @@ A collection of commonly used widgets.
<img
src=
"screenshot/state_tooltip.gif"
/>
<img
src=
"screenshot/state_tooltip.gif"
/>
</td>
</td>
</tr>
</tr>
<tr>
<td>
Flow Layout
</td>
<td>
<code>
FlowLayout
</code>
</td>
</tr>
<tr>
<td
colspan=
"2"
align=
"center"
>
<img
src=
"screenshot/flow_layout.gif"
/>
</td>
</tr>
<tr>
<tr>
<td>
<td>
Smooth Scroll Area
Smooth Scroll Area
...
...
screenshot/flow_layout.gif
0 → 100644
浏览文件 @
cb4d6803
195.5 KB
widgets/flow_layout/demo.py
0 → 100644
浏览文件 @
cb4d6803
# coding:utf-8
import
sys
from
PyQt5.QtWidgets
import
QApplication
,
QWidget
,
QPushButton
from
flow_layout
import
FlowLayout
class
Demo
(
QWidget
):
def
__init__
(
self
):
super
().
__init__
()
layout
=
FlowLayout
(
self
)
layout
.
setContentsMargins
(
30
,
30
,
30
,
30
)
layout
.
setVerticalSpacing
(
20
)
layout
.
setHorizontalSpacing
(
10
)
layout
.
addWidget
(
QPushButton
(
'aiko'
))
layout
.
addWidget
(
QPushButton
(
'刘静爱'
))
layout
.
addWidget
(
QPushButton
(
'柳井爱子'
))
layout
.
addWidget
(
QPushButton
(
'aiko 赛高'
))
layout
.
addWidget
(
QPushButton
(
'aiko 太爱啦😘'
))
self
.
resize
(
250
,
300
)
self
.
setStyleSheet
(
'Demo{background: white} QPushButton{padding: 5px 10px; font:15px "Microsoft YaHei"}'
)
if
__name__
==
'__main__'
:
app
=
QApplication
(
sys
.
argv
)
w
=
Demo
()
w
.
show
()
app
.
exec_
()
widgets/flow_layout/flow_layout.py
0 → 100644
浏览文件 @
cb4d6803
# coding:utf-8
from
PyQt5.QtCore
import
QSize
,
QPoint
,
Qt
,
QMargins
,
QRect
from
PyQt5.QtWidgets
import
QLayout
class
FlowLayout
(
QLayout
):
def
__init__
(
self
,
parent
=
None
):
super
().
__init__
(
parent
)
self
.
__items
=
[]
self
.
__verticalSpacing
=
10
self
.
__horizontalSpacing
=
10
self
.
__margins
=
QMargins
(
0
,
0
,
0
,
0
)
super
().
setContentsMargins
(
self
.
__margins
)
def
addItem
(
self
,
item
):
self
.
__items
.
append
(
item
)
def
count
(
self
):
return
len
(
self
.
__items
)
def
itemAt
(
self
,
index
:
int
):
if
0
<=
index
<
len
(
self
.
__items
):
return
self
.
__items
[
index
]
return
None
def
takeAt
(
self
,
index
:
int
):
if
0
<=
index
<
len
(
self
.
__items
):
return
self
.
__items
.
pop
(
index
)
return
None
def
removeAllWidgets
(
self
):
""" 从布局中移除所有的部件 """
while
self
.
__items
:
self
.
takeAt
(
0
)
def
expandingDirections
(
self
):
return
Qt
.
Orientation
(
0
)
def
hasHeightForWidth
(
self
):
return
True
def
heightForWidth
(
self
,
width
:
int
):
""" 根据宽度计算最小高度 """
return
self
.
__do_layout
(
QRect
(
0
,
0
,
width
,
0
),
False
)
def
setGeometry
(
self
,
rect
:
QRect
):
super
().
setGeometry
(
rect
)
self
.
__do_layout
(
rect
,
True
)
def
sizeHint
(
self
):
return
self
.
minimumSize
()
def
minimumSize
(
self
):
size
=
QSize
()
for
item
in
self
.
__items
:
size
=
size
.
expandedTo
(
item
.
minimumSize
())
m
=
self
.
__margins
size
+=
QSize
(
m
.
left
()
+
m
.
right
(),
m
.
top
()
+
m
.
bottom
())
return
size
def
setVerticalSpacing
(
self
,
spacing
:
int
):
""" 设置竖直方向的间距 """
self
.
__verticalSpacing
=
spacing
def
verticalSpacing
(
self
):
""" 返回竖直方向的间距 """
return
self
.
__verticalSpacing
def
setHorizontalSpacing
(
self
,
spacing
:
int
):
""" 设置水平方向的间距 """
self
.
__horizontalSpacing
=
spacing
def
horizontalSpacing
(
self
):
""" 返回水平方向间距 """
return
self
.
__horizontalSpacing
def
__do_layout
(
self
,
rect
:
QRect
,
move
:
bool
):
""" 根据大小调整小部件位置 """
margin
=
self
.
contentsMargins
()
x
=
rect
.
x
()
+
margin
.
left
()
y
=
rect
.
y
()
+
margin
.
top
()
rowHeight
=
0
spaceX
=
self
.
horizontalSpacing
()
spaceY
=
self
.
verticalSpacing
()
for
item
in
self
.
__items
:
nextX
=
x
+
item
.
sizeHint
().
width
()
+
spaceX
if
nextX
-
spaceX
>
rect
.
right
()
and
rowHeight
>
0
:
x
=
rect
.
x
()
+
margin
.
left
()
y
=
y
+
rowHeight
+
spaceY
nextX
=
x
+
item
.
sizeHint
().
width
()
+
spaceX
rowHeight
=
0
if
move
:
item
.
setGeometry
(
QRect
(
QPoint
(
x
,
y
),
item
.
sizeHint
()))
x
=
nextX
rowHeight
=
max
(
rowHeight
,
item
.
sizeHint
().
height
())
return
y
+
rowHeight
-
rect
.
y
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录