1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| void Label::paintEvent(QPaintEvent *e) { QPainter painter(this);
const qreal radius = 10; QRectF rect = QRect(10, 200, 20, 20);
QPainterPath path; path.moveTo(rect.bottomRight() - QPointF(0, radius)); path.lineTo(rect.topRight() + QPointF(0, radius)); path.arcTo(QRectF(QPointF(rect.topRight() - QPointF(radius * 2, 0)), QSize(radius * 2, radius *2)), 0, 90); path.lineTo(rect.topLeft() + QPointF(radius, 0)); path.arcTo(QRectF(QPointF(rect.topLeft()), QSize(radius * 2, radius * 2)), 90, 90); path.lineTo(rect.bottomLeft() - QPointF(0, radius)); path.arcTo(QRectF(QPointF(rect.bottomLeft() - QPointF(0, radius * 2)), QSize(radius * 2, radius * 2)), 180, 90); path.lineTo(rect.bottomLeft() + QPointF(radius, 0)); path.arcTo(QRectF(QPointF(rect.bottomRight() - QPointF(radius * 2, radius * 2)), QSize(radius * 2, radius * 2)), 270, 90);
painter.fillPath(path, QColor(Qt::red));
QPen pen = painter.pen(); pen.setColor(Qt::white); painter.setPen(pen); painter.drawText(rect, Qt::AlignCenter, QString::number(99));
{ painter.save(); const qreal radius = 10; QRectF rect = QRect(50, 200, 50, 20);
QPainterPath path;
path.moveTo(rect.bottomRight() - QPointF(0, radius)); path.lineTo(rect.topRight() + QPointF(0, radius)); path.arcTo(QRectF(QPointF(rect.topRight() - QPointF(radius * 2, 0)), QSize(radius * 2, radius *2)), 0, 90); path.lineTo(rect.topLeft() + QPointF(radius, 0)); path.arcTo(QRectF(QPointF(rect.topLeft()), QSize(radius * 2, radius * 2)), 90, 90); path.lineTo(rect.bottomLeft() - QPointF(0, radius)); path.arcTo(QRectF(QPointF(rect.bottomLeft() - QPointF(0, radius * 2)), QSize(radius * 2, radius * 2)), 180, 90); path.lineTo(rect.bottomLeft() + QPointF(radius, 0)); path.arcTo(QRectF(QPointF(rect.bottomRight() - QPointF(radius * 2, radius * 2)), QSize(radius * 2, radius * 2)), 270, 90);
painter.fillPath(path, QColor(Qt::red));
QPen pen = painter.pen(); pen.setColor(Qt::white); painter.setPen(pen); painter.drawText(rect, Qt::AlignCenter, QString::number(9999999)); painter.restore(); } }
|