def paint(self, painter, option, widget): w = self.w h = self.h key = QPainterPath() key.setFillRule(Qt.WindingFill) painter.save() painter.rotate(self.angle) key.moveTo(0.0, 0.0) key.lineTo(w, 0.0) key.lineTo(w, h) key.lineTo(0.0, h) painter.fillPath(key, self.color) painter.setPen(QPen(Qt.white, 1)) key.moveTo(0, 0) painter.drawLine(0, 0, w, 0) painter.drawLine(w, 0, w, h) painter.drawLine(w, h, 0, h) painter.drawLine(0, h, 0, 0) painter.setPen(Qt.white) metric = painter.fontMetrics() margin = 5 textBound = metric.boundingRect(self.text) painter.drawText(margin, h - margin, self.text) painter.restore()
def paint(self, painter, option, widget=None): """@reimp @public virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) """ #Q_UNUSED(option) #Q_UNUSED(widget) d = self.__d key = d.hash pm = QPixmap() if not QPixmapCache.find(key, pm): # Set up a convenient path path = QPainterPath() path.setFillRule(Qt.OddEvenFill) path.addEllipse(QPointF(d.actualOuterRadius, d.actualOuterRadius), d.actualOuterRadius, d.actualOuterRadius) path.addEllipse(QPointF(d.actualOuterRadius, d.actualOuterRadius), d.actualInnerRadius, d.actualInnerRadius) nActualDiameter = 2.0 * d.actualOuterRadius pm = QPixmap(nActualDiameter, nActualDiameter) pm.fill(Qt.transparent) p = QPainter(pm) # Draw the ring background p.setPen(Qt.NoPen) p.setBrush(d.backgroundColor) p.setRenderHint(QPainter.Antialiasing) p.drawPath(path) # Draw the ring foreground # TODO: Expose this gradient as Qml Property gradient = QConicalGradient(d.actualOuterRadius, d.actualOuterRadius, 0.0) gradient.setColorAt(0.0, Qt.transparent) gradient.setColorAt(0.05, d.foregroundColor) gradient.setColorAt(0.8, Qt.transparent) p.setBrush(gradient) p.drawPath(path) p.end() QPixmapCache.insert(key, pm) # Draw pixmap at center of item w, h = self.width(), self.height() sz = min(w, h) painter.drawPixmap(0.5 * (w - sz), 0.5 * (h - sz), pm)