@@ -12,6 +12,10 @@ class VocabularyPKSettingsDialog(QDialog):
1212 def __init__ (self , parent = None , settings = None ):
1313 super ().__init__ (parent )
1414 self .settings = settings or {}
15+
16+ self .update_theme_style ()
17+ qconfig .themeChanged .connect (self .update_theme_style )
18+
1519 self .initUI ()
1620
1721 def initUI (self ):
@@ -135,14 +139,14 @@ def initUI(self):
135139 settings_card_layout .addWidget (basic_group )
136140
137141 # 高级设置区域
138- advanced_group = QGroupBox ("高级设置" )
139- advanced_group .setFont (QFont (load_custom_font (), 12 ))
140- advanced_layout = QFormLayout (advanced_group )
142+ self . advanced_group = QGroupBox ("高级设置" )
143+ self . advanced_group .setFont (QFont (load_custom_font (), 12 ))
144+ advanced_layout = QFormLayout (self . advanced_group )
141145 advanced_layout .setLabelAlignment (Qt .AlignRight )
142146 advanced_layout .setFormAlignment (Qt .AlignLeft )
143147 advanced_layout .setSpacing (15 )
144148
145- advanced_group .setStyleSheet ("QGroupBox { border: 1px solid #cccccc; border-radius: 6px; margin-top: 12px; } "
149+ self . advanced_group .setStyleSheet ("QGroupBox { border: 1px solid #cccccc; border-radius: 6px; margin-top: 12px; } "
146150 "QGroupBox::title { subcontrol-origin: margin; left: 10px; padding: 0 3px 0 3px; }" )
147151
148152 # 练习模式选择
@@ -221,7 +225,7 @@ def initUI(self):
221225
222226 advanced_layout .addRow (countdown_label , self .countdown_widget )
223227
224- settings_card_layout .addWidget (advanced_group )
228+ settings_card_layout .addWidget (self . advanced_group )
225229
226230 main_layout .addWidget (settings_card )
227231
@@ -260,7 +264,7 @@ def on_delete_vocabulary_clicked(self):
260264 content = "没有选择可删除的词汇表" ,
261265 duration = 3000 ,
262266 parent = self
263- ). show ()
267+ )
264268 return
265269
266270 # 确认删除
@@ -306,23 +310,80 @@ def on_delete_vocabulary_clicked(self):
306310 content = f"已成功删除词汇表: { current_vocabulary } " ,
307311 duration = 3000 ,
308312 parent = self
309- ). show ()
313+ )
310314 else :
311315 # 显示删除失败的提示
312316 InfoBar .error (
313317 title = "删除失败" ,
314318 content = f"删除词汇表 '{ current_vocabulary } ' 失败,请重试" ,
315319 duration = 3000 ,
316320 parent = self
317- ). show ()
321+ )
318322 else :
319323 # 如果父窗口不存在或没有删除词汇表方法,显示错误提示
320324 InfoBar .error (
321325 title = "错误" ,
322326 content = "无法删除词汇表,请重试" ,
323327 duration = 3000 ,
324328 parent = self
325- ).show ()
329+ )
330+
331+ def update_theme_style (self ):
332+ """根据当前主题更新样式"""
333+ if qconfig .theme == Theme .AUTO :
334+ lightness = QApplication .palette ().color (QPalette .Window ).lightness ()
335+ is_dark = lightness <= 127
336+ else :
337+ is_dark = qconfig .theme == Theme .DARK
338+
339+ colors = {'text' : '#F5F5F5' , 'bg' : '#111116' , 'title_bg' : '#2D2D2D' } if is_dark else {'text' : '#111116' , 'bg' : '#F5F5F5' , 'title_bg' : '#E0E0E0' }
340+ self .setStyleSheet (f"""
341+ QDialog {{ background-color: { colors ['bg' ]} ; border-radius: 5px; }}
342+ #CustomTitleBar {{ background-color: { colors ['title_bg' ]} ; }}
343+ #TitleLabel {{ color: { colors ['text' ]} ; font-weight: bold; padding: 5px; }}
344+ #CloseButton {{
345+ background-color: transparent;
346+ color: { colors ['text' ]} ;
347+ border-radius: 4px;
348+ font-weight: bold;
349+ border: none;
350+ }}
351+ #CloseButton:hover {{
352+ background-color: #ff4d4d;
353+ color: white;
354+ border: none;
355+ }}
356+ QLabel, QPushButton, QTextEdit {{ color: { colors ['text' ]} ; }}
357+ QLineEdit {{
358+ background-color: { colors ['bg' ]} ;
359+ color: { colors ['text' ]} ;
360+ border: 1px solid #555555;
361+ border-radius: 4px;
362+ padding: 5px;
363+ }}
364+ QPushButton {{
365+ background-color: { colors ['bg' ]} ;
366+ color: { colors ['text' ]} ;
367+ border: 1px solid #555555;
368+ border-radius: 4px;
369+ padding: 5px;
370+ }}
371+ QPushButton:hover {{ background-color: #606060; }}
372+ QComboBox {{
373+ background-color: { colors ['bg' ]} ;
374+ color: { colors ['text' ]} ;
375+ border: 1px solid #555555;
376+ border-radius: 4px;
377+ padding: 5px;
378+ }}
379+ QGroupBox {{ color: { colors ['text' ]} ; }}
380+ QGroupBox::title {{ color: { colors ['text' ]} ; }}
381+ """ )
382+
383+ # 更新高级设置QGroupBox的字体颜色
384+ if hasattr (self , 'advanced_group' ):
385+ self .advanced_group .setStyleSheet (f"QGroupBox {{ color: { colors ['text' ]} ; border: 1px solid #cccccc; border-radius: 6px; margin-top: 12px; }} "
386+ f"QGroupBox::title {{ subcontrol-origin: margin; left: 10px; padding: 0 3px 0 3px; color: { colors ['text' ]} ; }}" )
326387
327388 def on_import_vocabulary_clicked (self ):
328389 """导入词汇表按钮点击事件处理函数"""
@@ -365,7 +426,7 @@ def on_import_vocabulary_clicked(self):
365426 content = "无法导入词汇表,请重试" ,
366427 duration = 3000 ,
367428 parent = self
368- ). show ()
429+ )
369430
370431 def get_settings (self ):
371432 """获取设置值"""
0 commit comments