基于当前设置主题颜色 :param cls: :param color: 背景颜色 :param widget: 指定控件
(cls, color, widget=None, replaces={})
| 316 | |
| 317 | @classmethod |
| 318 | def loadColourfulTheme(cls, color, widget=None, replaces={}): |
| 319 | """基于当前设置主题颜色 |
| 320 | :param cls: |
| 321 | :param color: 背景颜色 |
| 322 | :param widget: 指定控件 |
| 323 | """ |
| 324 | # 加载主题取样式 |
| 325 | path = cls.stylePath('Default') |
| 326 | AppLog.info('stylePath: {}'.format(path)) |
| 327 | try: |
| 328 | styleSheet = open(path, 'rb').read().decode('utf-8', |
| 329 | errors='ignore') |
| 330 | # 需要替换部分样式 |
| 331 | colorstr = GradientUtils.styleSheetCode(color) |
| 332 | if isinstance(color, QLinearGradient) or isinstance( |
| 333 | color, QRadialGradient) or isinstance( |
| 334 | color, QConicalGradient): |
| 335 | color = color.stops()[0][1] |
| 336 | # 替换name |
| 337 | templates = StyleGradientTemplate |
| 338 | for name, value in replaces.items(): |
| 339 | templates = templates.replace(name, value) |
| 340 | |
| 341 | styleSheet += templates.format(color.red(), color.green(), |
| 342 | color.blue(), colorstr) |
| 343 | widget = widget or QApplication.instance() |
| 344 | widget.setStyleSheet(styleSheet) |
| 345 | except Exception as e: |
| 346 | AppLog.exception(e) |
| 347 | |
| 348 | @classmethod |
| 349 | def loadPictureTheme(cls, image=None, widget=None, replaces={}): |
no test coverage detected