troublebar.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. '''
  4. @文件 :troublebar.py
  5. @时间 :2022/01/22 10:06:04
  6. @作者 :None
  7. @版本 :1.0
  8. @说明 :故障主题
  9. '''
  10. from utils.qt import QProgressBar, QPainter
  11. # from random import randint
  12. StyleSheet = """
  13. /*设置红色进度条*/
  14. #RedProgressBar {
  15. text-align: center; /*进度值居中*/
  16. }
  17. #RedProgressBar::chunk {
  18. background-color: #F44336;
  19. }
  20. #GreenProgressBar {
  21. min-height: 12px;
  22. max-height: 12px;
  23. border-radius: 6px;
  24. }
  25. #GreenProgressBar::chunk {
  26. border-radius: 6px;
  27. background-color: #009688;
  28. }
  29. #BlueProgressBar {
  30. border: 2px solid #2196F3;/*边框以及边框颜色*/
  31. border-radius: 5px;
  32. background-color: #E0E0E0;
  33. }
  34. BlueProgressBar::chunk {
  35. background-color: #2196F3;
  36. width: 10px; /*区块宽度*/
  37. margin: 0.5px;
  38. }
  39. """
  40. class TroubleProgressBar(QProgressBar):
  41. def __init__(self, parent=None):
  42. super(TroubleProgressBar, self).__init__(parent)
  43. self.setTextVisible(False)
  44. self.setStyleSheet("QProgressBar::chunk{background:qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0.0 green, stop: 0 yellow, stop: 1 red)}")
  45. def paintEvent(self, event):
  46. """绘制按钮"""
  47. super(TroubleProgressBar, self).paintEvent(event)
  48. # 绘制准备工作,启用反锯齿
  49. # 创建绘制器并设置抗锯齿和图片流畅转换
  50. painter = QPainter(self)
  51. painter.setRenderHints(QPainter.Antialiasing | QPainter.TextAntialiasing)