Skip to content

Commit

Permalink
hotfix: dynamic adding pages supports
Browse files Browse the repository at this point in the history
  • Loading branch information
ChinaIceF committed Sep 10, 2024
1 parent c541453 commit dfc298d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions siui/templates/application/components/page_view/page_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def __init__(self, *args, **kwargs):
# 创建容器用于放置按钮
self.container = SiDenseVContainer(self)
self.container.setSpacing(8)
self.container.setAlignment(Qt.AlignCenter)
self.container.setShrinking(False)
self.container.setAlignment(Qt.AlignHCenter)

# 所有按钮
self.buttons = []
Expand All @@ -103,20 +104,22 @@ def addPageButton(self, svg_data, hint, func_when_active, side="top"):
:param func_when_active: 当被激活时调用的函数
:param side: 添加在哪一侧
"""
new_page_button = PageButton(self)
new_page_button = PageButton(self.container)
new_page_button.setIndex(self.maximumIndex())
new_page_button.setStyleSheet("background-color: #20FF0000")
new_page_button.resize(40, 40)
new_page_button.setHint(hint)
new_page_button.attachment().setSvgSize(20, 20)
new_page_button.attachment().load(svg_data)
new_page_button.activated.connect(func_when_active)
new_page_button.show()

# 绑定索引切换信号,当页面切换时,会使按钮切换为 checked 状态
self.indexChanged.connect(new_page_button.on_index_changed)

# 新按钮添加到容器中
self.container.addWidget(new_page_button, side=side)
self.container.arrangeWidget()
self.setMaximumIndex(self.maximumIndex() + 1)

self.buttons.append(new_page_button)
Expand Down

0 comments on commit dfc298d

Please sign in to comment.