Skip to content

Commit 7ab29a5

Browse files
authored
Merge pull request ChinaIceF#67 from ChinaIceF/reconst
添加 SiTitledWidgetGroup 类
2 parents 6f410cd + 482a6f1 commit 7ab29a5

File tree

8 files changed

+134
-24
lines changed

8 files changed

+134
-24
lines changed

examples/Gallery/components/ExperimentField.py

+27-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import SiliconUI.SiGlobal as SiGlobal
22
from SiliconUI.SiFont import *
3-
from siui.components import SiOptionCardLinear, SiOptionCardPlane, SiSliderH, SiProgressBar
3+
from siui.components import SiOptionCardLinear, SiOptionCardPlane, SiSliderH, SiProgressBar, SiTitledWidgetGroup
44
from siui.components.widgets import (
55
SiCheckBox,
66
SiDenseHContainer,
@@ -134,11 +134,16 @@ def __init__(self, parent):
134134
self.button_layout2.addItem(self.switch_test)
135135

136136
self.container_h = SiDenseHContainer(self)
137+
self.container_h.setFixedHeight(128)
138+
self.container_h.setAdjustWidgetsSize(True)
137139
self.container_h.setStyleSheet("background-color: #05ffffff")
138140

139141
self.container_v_left = SiDenseVContainer(self)
142+
self.container_v_left.setFixedWidth(128)
140143
self.container_v_left.setStyleSheet("background-color: #05ffffff")
144+
141145
self.container_v_right = SiDenseVContainer(self)
146+
self.container_v_right.setFixedWidth(128)
142147
self.container_v_right.setStyleSheet("background-color: #05ffffff")
143148

144149
self.button_lefttop = SiPushButton(self)
@@ -210,6 +215,9 @@ def __init__(self, parent):
210215
self.scrollarea.setFixedHeight(256)
211216
self.scrollarea.setWidget(self.alabel)
212217

218+
# 新测试
219+
self.titled_widget_group = SiTitledWidgetGroup(self)
220+
213221
self.button_for_option_card = SiPushButton(self)
214222
self.button_for_option_card.attachment().setText("刷新")
215223
self.button_for_option_card.resize(128, 32)
@@ -231,7 +239,6 @@ def __init__(self, parent):
231239
self.optioncard2.addWidget(self.button_for_option_card2)
232240

233241
self.optioncard3 = SiOptionCardPlane(self)
234-
self.optioncard3.setFixedHeight(200)
235242
self.optioncard3.setTitle("平面选项卡")
236243

237244
self.button_for_test = SiPushButton(self)
@@ -244,7 +251,8 @@ def __init__(self, parent):
244251

245252
self.optioncard3.body().addWidget(self.button_for_test)
246253
self.optioncard3.body().addWidget(self.button_for_test2)
247-
254+
self.optioncard3.body().addPlaceholder(24 - 8)
255+
self.optioncard3.adjustSize()
248256

249257
self.new_slider = SiSliderH(self)
250258
#self.new_slider.setStyleSheet("background-color: #20FF0000")
@@ -261,18 +269,27 @@ def __init__(self, parent):
261269
self.lineedit = SiLineEdit(self)
262270
self.lineedit.setFixedHeight(32)
263271

272+
self.titled_widget_group.setFixedWidth(800)
273+
#self.titled_widget_group.setStyleSheet("background-color: #20FF0000")
274+
self.titled_widget_group.addTitle("选项卡")
275+
self.titled_widget_group.addWidget(self.optioncard)
276+
self.titled_widget_group.addWidget(self.optioncard2)
277+
self.titled_widget_group.addWidget(self.optioncard3)
278+
self.titled_widget_group.addTitle("滑条")
279+
self.titled_widget_group.addWidget(self.new_slider)
280+
self.titled_widget_group.addTitle("进度条")
281+
self.titled_widget_group.addWidget(self.new_progressbar)
282+
self.titled_widget_group.addWidget(self.random_progress_button)
283+
self.titled_widget_group.addTitle("输入框")
284+
self.titled_widget_group.addWidget(self.lineedit)
285+
264286
self.stack_reconstruct_test.addItem(self.reconstruct_discription)
265287
self.stack_reconstruct_test.addItem(self.button_layout)
266288
self.stack_reconstruct_test.addItem(self.button_layout2)
267289
self.stack_reconstruct_test.addItem(self.container_h)
268290
self.stack_reconstruct_test.addItem(self.scrollarea)
269-
self.stack_reconstruct_test.addItem(self.optioncard)
270-
self.stack_reconstruct_test.addItem(self.optioncard2)
271-
self.stack_reconstruct_test.addItem(self.optioncard3)
272-
self.stack_reconstruct_test.addItem(self.new_slider)
273-
self.stack_reconstruct_test.addItem(self.new_progressbar)
274-
self.stack_reconstruct_test.addItem(self.random_progress_button)
275-
self.stack_reconstruct_test.addItem(self.lineedit)
291+
self.stack_reconstruct_test.addItem(self.titled_widget_group)
292+
276293
#self.stack_reconstruct_test.addItem(self.test_label)
277294

278295
self.addItem(self.discription)

siui/components/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from siui.components.option_card import *
2-
from siui.components.slider import *
32
from siui.components.progress_bar import *
4-
from siui.components.widgets import *
3+
from siui.components.slider import *
4+
from siui.components.titled_widget_group import *
5+
from siui.components.widgets import *

siui/components/option_card/abstracts/option_card.py

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ def footer(self):
6060
"""
6161
return self.footer_
6262

63+
def adjustSize(self):
64+
self.resize(self.width(), self.header().height() + self.body().height() + self.footer().height() + 3)
65+
6366
def reloadStyleSheet(self):
6467
super().reloadStyleSheet()
6568

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from siui.components.titled_widget_group.titled_widget_group import SiTitledWidgetGroup
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
from siui.components.widgets.container import SiDenseVContainer
2+
from siui.components.widgets.label import SiLabel
3+
from siui.core.globals import SiGlobal
4+
5+
6+
class GroupTitle(SiLabel):
7+
def __init__(self, *args, **kwargs):
8+
super().__init__(*args, **kwargs)
9+
10+
self.setFixedHeight(25)
11+
12+
# 标题文字
13+
self.title_label = SiLabel(self)
14+
self.title_label.setFont(SiGlobal.siui.fonts["M_BOLD"])
15+
self.title_label.setFixedHeight(25)
16+
self.title_label.setAutoAdjustSize(True)
17+
18+
# 标题高光,显示在文字下方
19+
self.title_highlight = SiLabel(self)
20+
self.title_highlight.lower()
21+
self.title_highlight.setFixedStyleSheet("border-radius: 4px")
22+
23+
# 标题指示器,显示在文字左侧
24+
self.title_indicator = SiLabel(self)
25+
self.title_indicator.resize(5, 18)
26+
self.title_indicator.setFixedStyleSheet("border-radius: 2px")
27+
28+
def reloadStyleSheet(self):
29+
super().reloadStyleSheet()
30+
31+
self.setStyleSheet("background-color: transparent")
32+
self.title_label.setStyleSheet("color: {}".format(SiGlobal.siui.colors["TEXT_A"]))
33+
self.title_indicator.setStyleSheet("background-color: {}".format(SiGlobal.siui.colors["TITLE_INDICATOR"]))
34+
self.title_highlight.setStyleSheet("background-color: {}".format(SiGlobal.siui.colors["TITLE_HIGHLIGHT"]))
35+
36+
def setText(self, text: str):
37+
self.title_label.setText(text)
38+
self.adjustSize()
39+
40+
def adjustSize(self):
41+
self.resize(self.title_label.width() + 12, self.height())
42+
43+
def resizeEvent(self, event):
44+
super().resizeEvent(event)
45+
46+
self.title_indicator.move(0, 4)
47+
self.title_label.move(12, 0)
48+
self.title_highlight.setGeometry(12, 12, self.title_label.width() + 4, 13)
49+
50+
51+
class SiTitledWidgetGroup(SiDenseVContainer):
52+
def __init__(self, *args, **kwargs):
53+
super().__init__(*args, **kwargs)
54+
55+
self.setShrinking(True)
56+
self.setAdjustWidgetsSize(True)
57+
self.setSpacing(8)
58+
59+
def addTitle(self, title):
60+
"""
61+
添加新标题,这将创建一个标题组件并添加到自身中
62+
:param title: 标题文字
63+
"""
64+
if len(self.widgets_top) > 0:
65+
self.addPlaceholder(16)
66+
67+
new_title = GroupTitle(self)
68+
new_title.setText(title)
69+
self.addWidget(new_title)
70+
71+
def addWidget(self, widget, side="top"):
72+
super().addWidget(widget, side)
73+
try:
74+
widget.resized.connect(self._on_child_resized)
75+
except: # noqa: E722
76+
pass
77+
# print(f"子控件 {widget} 似乎不具有正确形式的 resized 信号(pyqtSignal(list))")
78+
79+
def _on_child_resized(self, _):
80+
self.adjustSize()

siui/components/widgets/button.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ def __init__(self, *args, **kwargs):
155155
self.setAttachment(self.label)
156156

157157
# 设置状态颜色为主题色
158-
self.setStateColor(Color.transparency(SiGlobal.siui.colors["THEME_TRANSITION_B"], 0.2),
159-
SiGlobal.siui.colors["THEME_TRANSITION_B"])
158+
self.setStateColor(Color.transparency(SiGlobal.siui.colors["THEME"], 0.2),
159+
SiGlobal.siui.colors["THEME"])
160160

161161
def reloadStyleSheet(self):
162162
super().reloadStyleSheet()
@@ -264,7 +264,7 @@ def _toggled_handler(self, check: bool):
264264

265265
# 禁止其切换模式,防止被取消选择
266266
self.indicator.setCheckable(False)
267-
self.indicator_label.setStyleSheet(f"border: 4px solid {SiGlobal.siui.colors['THEME_TRANSITION_B']}")
267+
self.indicator_label.setStyleSheet(f"border: 4px solid {SiGlobal.siui.colors['THEME']}")
268268
else:
269269
# 如果被选中状态为假,就允许其切换模式
270270
self.indicator.setCheckable(True)
@@ -372,7 +372,7 @@ def isChecked(self):
372372
def _toggled_handler(self, check: bool):
373373
if check is True:
374374
self.indicator_icon.setVisible(True)
375-
self.indicator_label.setStyleSheet(f"background-color: {SiGlobal.siui.colors['THEME_TRANSITION_B']}")
375+
self.indicator_label.setStyleSheet(f"background-color: {SiGlobal.siui.colors['THEME']}")
376376
else:
377377
self.indicator_icon.setVisible(False)
378378
self.indicator_label.setStyleSheet(f"border: 1px solid {SiGlobal.siui.colors['TEXT_D']}")

siui/components/widgets/container.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,14 @@ def adjustSize(self):
169169
preferred_w = total_used
170170

171171
# 计算所有控件中高度最大的,以保证所有控件在容器中
172-
preferred_h = max([obj.height() for obj in self.widgets_left + self.widgets_right])
172+
# preferred_h = max([obj.height() for obj in self.widgets_left + self.widgets_right])
173173

174174
if self.shrinking is False:
175175
# 和原本自身的尺寸比价,取最大者
176176
preferred_w = max(preferred_w, self.width())
177-
preferred_h = max(preferred_h, self.height())
177+
# preferred_h = max(preferred_h, self.height())
178178

179-
self.resize(preferred_w, preferred_h)
179+
self.resize(preferred_w, self.height())
180180

181181

182182
class SiDenseVContainer(SiLabel):
@@ -230,13 +230,13 @@ def setSpacing(self, spacing: int):
230230
def addPlaceholder(self, length, side="top"):
231231
"""
232232
添加占位符
233-
:param length: 占位符的宽度
233+
:param length: 占位符的高
234234
:param side: 添加到哪一侧
235235
:return:
236236
"""
237237
new_label = SiLabel(self)
238238
new_label.setVisible(False)
239-
new_label.resize(length, 0)
239+
new_label.resize(0, length)
240240
self.addWidget(new_label, side=side)
241241

242242
def addWidget(self, widget, side="top"):
@@ -347,14 +347,14 @@ def adjustSize(self):
347347
preferred_h = total_used
348348

349349
# 计算所有控件中宽度最大的,以保证所有控件在容器中
350-
preferred_w = max([obj.width() for obj in self.widgets_bottom + self.widgets_top])
350+
# preferred_w = max([obj.width() for obj in self.widgets_bottom + self.widgets_top])
351351

352352
if self.shrinking is False:
353353
# 和原本自身的尺寸比价,取最大者
354-
preferred_w = max(preferred_w, self.width())
354+
# preferred_w = max(preferred_w, self.width())
355355
preferred_h = max(preferred_h, self.height())
356356

357-
self.resize(preferred_w, preferred_h)
357+
self.resize(self.width(), preferred_h)
358358

359359

360360
class SiStackedContainer(SiLabel):

siui/gui/colorsets.py

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ class ColorsetDark:
88
# SVG 颜色
99
colors["SVG_A"] = "#FFFFFF"
1010

11+
# 主题色
12+
colors["THEME"] = "#855198"
13+
1114
# 过渡主题色
1215
colors["THEME_TRANSITION_A"] = "#52389a"
1316
colors["THEME_TRANSITION_B"] = "#9c4e8b"
@@ -28,6 +31,11 @@ class ColorsetDark:
2831
colors["TEXT_C"] = "#CFCFCF"
2932
colors["TEXT_D"] = "#AFAFAF"
3033

34+
# 标题相关
35+
colors["TITLE_INDICATOR"] = "#c58bc2"
36+
colors["TITLE_HIGHLIGHT"] = "#52324E"
37+
38+
3139
# ============= 控件 =============
3240
# 按钮
3341
# 按钮鼠标相关

0 commit comments

Comments
 (0)