| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- """
- 统一的按钮样式定义
- """
- from PyQt5.QtWidgets import QPushButton
- from PyQt5.QtGui import QFont
- def get_button_style(color_type: str) -> str:
- """
- 获取按钮样式
- :param color_type: 'green' | 'blue' | 'normal'
- :return: 样式字符串
- """
- base_style = "border-radius: 5px; padding: 8px 16px;"
-
- if color_type == 'green':
- return f"""
- {base_style}
- background-color: #4CAF50;
- color: white;
- border: none;
- """
- elif color_type == 'blue':
- return f"""
- {base_style}
- background-color: #2196F3;
- color: white;
- border: none;
- """
- else: # normal
- return f"""
- {base_style}
- background-color: #f5f5f5;
- color: #333;
- border: 1px solid #ccc;
- """
- def apply_button_style(button: QPushButton, color_type: str):
- """
- 应用按钮样式
- :param button: QPushButton实例
- :param color_type: 'green' | 'blue' | 'normal'
- """
- button.setStyleSheet(get_button_style(color_type))
- def get_button_color_type(button_text: str) -> str:
- """
- 根据按钮文本自动判断应该使用哪种颜色
- :param button_text: 按钮文本
- :return: 'green' | 'blue' | 'normal'
- """
- # 绿色按钮:确认、保存类操作
- green_keywords = ['保存', '确定', '新增', '登录', '提交', '确认']
-
- # 蓝色按钮:主要操作、重要功能
- blue_keywords = ['生成', '地磅单', '打印', '读毛重', '读皮重', '当前时间']
-
- for keyword in green_keywords:
- if keyword in button_text:
- return 'green'
-
- for keyword in blue_keywords:
- if keyword in button_text:
- return 'blue'
-
- # 默认普通样式
- return 'normal'
|