Qt☞之QPainterPath

14 篇文章 0 订阅

QPainterPath

QPainterPath类为绘画操作提供了一个容器,允许构造和重用图形形状。

代码一加运算:

void MainWindow::painterPathDemo(QPainter *painter)
{
    painter->save();
    QPainterPath path;
    path.moveTo(200,200);
    path.lineTo(220,240);
    path.cubicTo(200,0,50,90,100,120);
    QPainterPath pathE;
    pathE.addEllipse(-100,-100,200,200);
    QPainterPath pathR;
    pathR.addRect(0,0,100,100);

    painter->drawPath(/*path+*/pathR+pathE);
    painter->restore();
}

演示图片:

代码二加运算: 

void MainWindow::painterPathDemo(QPainter *painter)
{
    painter->save();
    QPainterPath path;
    path.moveTo(200,200);
    path.lineTo(220,240);
    path.cubicTo(200,0,50,90,100,120);
    QPainterPath pathE;
    pathE.addEllipse(-100,-100,200,200);
    QPainterPath pathR;
    pathR.addRect(0,0,100,100);

    painter->drawPath(path+pathR+pathE);
    painter->restore();
}

演示图片:

代码三减运算Ⅰ:

void MainWindow::painterPathDemo(QPainter *painter)
{
    painter->save();
    QPainterPath path;
    path.moveTo(200,200);
    path.lineTo(220,240);
    path.cubicTo(200,0,50,90,100,120);
    QPainterPath pathE;
    pathE.addEllipse(-100,-100,200,200);
    QPainterPath pathR;
    pathR.addRect(0,0,100,100);

    painter->drawPath(/*path+*/pathR-pathE);
    painter->restore();
}

 

 代码三减运算Ⅱ:

void MainWindow::painterPathDemo(QPainter *painter)
{
    painter->save();
    QPainterPath path;
    path.moveTo(200,200);
    path.lineTo(220,240);
    path.cubicTo(200,0,50,90,100,120);
    QPainterPath pathE;
    pathE.addEllipse(-100,-100,200,200);
    QPainterPath pathR;
    pathR.addRect(0,0,100,100);

    painter->drawPath(/*path+*/pathE-pathR);
    painter->restore();
}

 

代码四或运算:

void MainWindow::painterPathDemo(QPainter *painter)
{
    painter->save();
    QPainterPath path;
    path.moveTo(200,200);
    path.lineTo(220,240);
    path.cubicTo(200,0,50,90,100,120);
    QPainterPath pathE;
    pathE.addEllipse(-100,-100,200,200);
    QPainterPath pathR;
    pathR.addRect(0,0,100,100);

    painter->drawPath(/*path+*/pathR|pathE);
    painter->restore();
}

 

代码五与运算:

void MainWindow::painterPathDemo(QPainter *painter)
{
    painter->save();
    QPainterPath path;
    path.moveTo(200,200);
    path.lineTo(220,240);
    path.cubicTo(200,0,50,90,100,120);
    QPainterPath pathE;
    pathE.addEllipse(-100,-100,200,200);
    QPainterPath pathR;
    pathR.addRect(0,0,100,100);

    painter->drawPath(/*path+*/pathR&pathE);
    painter->restore();
}

 

总结:

1.QPainterPath可以进行加减与或等运算。

QPainterPath path1,path2;
path1+path2  ==  void addPath(const QPainterPath &path);

path1-path2 == QPainterPath subtracted(const QPainterPath &p) const;

2.QPainterPath进行相减,如path1-path2,将path1与path2重合的部分去掉后,只保留path1剩余的部分。

3.或运算等同于加运算,可以理解为将重合的部分去掉,不重合的部分保留。

4.与运算保留重合部分,可以理解为将路径上共有的容器保留下来。

上述是部分源代码,整个代码连接如下:

https://download.csdn.net/download/weixin_41882459/12040558

该代码包含了线性渐变、圆锥渐变、半径渐变、填充图,擦除图,绘制饼图,绘制三角形,圆,qpainterpath的例子等代码。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

凌武贰玖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值