void QPainterPath::cubicTo(const QPointF & c1, const QPointF & c2, const QPointF & endPoint)
在当前位置和给定终点,通过控制点c1和c2添加一个立方体Bezier曲线。在添加曲线后,当前位置变为曲线的终点。
QLinearGradient myGradient;
QPen myPen;
QPainterPath myPath;
myPath.cubicTo(c1, c2, endPoint);
QPainter painter(this);
painter.setBrush(myGradient);
painter.setPen(myPen);
painter.drawPath(myPath);
void QPainterPath::arcTo(const QRectF & rectangle, qreal startAngle, qreal sweepLength)
void Widget::paintEvent(QPaintEvent *e)
{
QPainterPath path;
path.moveTo(150,150);
path.arcTo(50,50,200,200,30,-90);
QPainterPath path1;
path1.moveTo(150,150);
path1.arcTo(50,50,200,200,-30,90);
QPainterPath path3;
path3=path.united(path1);
QPainter painter(this);
QPen pen(QColor(255,0,0),2);
painter.setPen(pen);
painter.drawRect(50,50,200,200);
painter.setBrush(Qt::red);
painter.drawPath(path3);
painter.setBrush(Qt::yellow);
painter.drawPath(path1);
}
本文介绍如何在Qt环境中利用QPainterPath结合控制点绘制立方体Bezier曲线,并展示最终的绘图效果。

3354

被折叠的 条评论
为什么被折叠?



