| 95 | self.animationGroup.start() |
| 96 | |
| 97 | def paintEvent(self, event): |
| 98 | super(BubbleLabel, self).paintEvent(event) |
| 99 | painter = QPainter(self) |
| 100 | painter.setRenderHint(QPainter.Antialiasing) # 抗锯齿 |
| 101 | |
| 102 | rectPath = QPainterPath() # 圆角矩形 |
| 103 | triPath = QPainterPath() # 底部三角形 |
| 104 | |
| 105 | height = self.height() - 8 # 往上偏移8 |
| 106 | rectPath.addRoundedRect(QRectF(0, 0, self.width(), height), 5, 5) |
| 107 | x = self.width() / 5 * 4 |
| 108 | triPath.moveTo(x, height) # 移动到底部横线4/5处 |
| 109 | # 画三角形 |
| 110 | triPath.lineTo(x + 6, height + 8) |
| 111 | triPath.lineTo(x + 12, height) |
| 112 | |
| 113 | rectPath.addPath(triPath) # 添加三角形到之前的矩形上 |
| 114 | |
| 115 | # 边框画笔 |
| 116 | painter.setPen(QPen(self.BorderColor, 1, Qt.SolidLine, |
| 117 | Qt.RoundCap, Qt.RoundJoin)) |
| 118 | # 背景画刷 |
| 119 | painter.setBrush(self.BackgroundColor) |
| 120 | # 绘制形状 |
| 121 | painter.drawPath(rectPath) |
| 122 | # 三角形底边绘制一条线保证颜色与背景一样 |
| 123 | painter.setPen(QPen(self.BackgroundColor, 1, |
| 124 | Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) |
| 125 | painter.drawLine(x, height, x + 12, height) |
| 126 | |
| 127 | def windowOpacity(self): |
| 128 | return super(BubbleLabel, self).windowOpacity() |