| 53 | |
| 54 | |
| 55 | class ToolTipWidget(QWidget): |
| 56 | Cache = {} |
| 57 | |
| 58 | def __init__(self, *args, **kwargs): |
| 59 | super(ToolTipWidget, self).__init__(*args, **kwargs) |
| 60 | self.setAttribute(Qt.WA_StyledBackground, True) |
| 61 | self.setStyleSheet( |
| 62 | "ToolTipWidget{background: rgba(50, 50, 50, 100);}") |
| 63 | layout = QVBoxLayout(self) |
| 64 | self.titleLabel = QLabel(self, styleSheet="color:white;") |
| 65 | layout.addWidget(self.titleLabel) |
| 66 | |
| 67 | def updateUi(self, title, bars): |
| 68 | self.titleLabel.setText(title) |
| 69 | for bar, value in bars: |
| 70 | if bar not in self.Cache: |
| 71 | item = ToolTipItem( |
| 72 | bar.color(), |
| 73 | (bar.label() or "-") + ":" + str(value), self) |
| 74 | self.layout().addWidget(item) |
| 75 | self.Cache[bar] = item |
| 76 | else: |
| 77 | self.Cache[bar].setText( |
| 78 | (bar.label() or "-") + ":" + str(value)) |
| 79 | brush = bar.brush() |
| 80 | color = brush.color() |
| 81 | self.Cache[bar].setVisible(color.alphaF() == 1.0) # 隐藏那些不可用的项 |
| 82 | self.adjustSize() # 调整大小 |
| 83 | |
| 84 | |
| 85 | class GraphicsProxyWidget(QGraphicsProxyWidget): |