如何使用QPen与QpainterPath
How to use QPen with QpainterPath?
我有一个代码:
QPainterPath groupPath;
QPen pen; // new
pen.setCosmetic(1); // new
groupPath.setPen(pen); // error (error: class "QPainterPath" has no member "setPen")
groupPath.moveTo(60.0, 40.0);
groupPath.arcTo(40.0, 35.0, 40.0, 10.0, 180.0, 180.0);
groupPath.moveTo(40.0, 40.0);
groupPath.lineTo(40.0, 80.0);
groupPath.arcTo(40.0, 75.0, 40.0, 10.0, 0.0, 180.0);
groupPath.lineTo(80.0, 80.0);
groupPath.lineTo(80.0, 40.0);
groupPath.closeSubpath();
如何使用setPen在我的代码中使用化妆品?
你不能在QPainterPath
上使用setPen()
,因为它不是画家,它只是一个路径。
你应该创建一个QPainter
,使用setPen()
,然后绘制路径:
QPainter painter(this);
QPen pen;
pen.setCosmetic(true);
painter.setPen(pen);
QPainterPath groupPath
groupPath.moveTo(60.0, 40.0);
groupPath.arcTo(40.0, 35.0, 40.0, 10.0, 180.0, 180.0);
groupPath.moveTo(40.0, 40.0);
groupPath.lineTo(40.0, 80.0);
groupPath.arcTo(40.0, 75.0, 40.0, 10.0, 0.0, 180.0);
groupPath.lineTo(80.0, 80.0);
groupPath.lineTo(80.0, 40.0);
groupPath.closeSubpath();
painter.drawPath(groupPath);
同样,正如@Andreas所说,pen.setCosmetic(true)
是不需要的,因为QPen()
的默认构造函数创建了一个宽度为0
的笔,这已经是Cosmetic。
不知道你的实际问题是什么,但一些备注:
- 实际上
QPen::setCosmetic()
需要bool
参数;1
可以,但true
是正确的。 - 通过默认构造器 创建时,新创建的
- 宽度为0的
QPen
s默认为装饰性
QPen
s的宽度为0因此,pen.setCosmetic(true)
不会有任何影响,你的笔应该是装饰性的(意思是,无论如何,有相同的宽度独立于比例因子)。
最后,正如@zakinster所提到的,QPainterPath
没有setPen()
方法。
相关文章:
- Write QPainterPath to XML
- 如何将QPixMap转换为QPainterPath,反之亦然
- 有效地在 QPainterPath 周围绘制文本
- 派生的QPainterPath,QPainter性能迅速下降
- QPainterPath QTransform::map
- QVariant conversion to QPainterPath
- 检查QPainterPath中是否存在点
- QPainterPath 和 QPoint 之间的最短距离
- QPen in Orange?
- 如何决定由 painter.drawPath(QPainterPath) 绘制的元素类型
- Qt4,QPainterPath的直接分配不起作用(未解决的外部)
- 缩放和移动QPainterPath
- 如何在QPainterPath中描边
- 如何使用QPen与QpainterPath
- Qt QPainterpath.h errors
- QPainterPath文本在打印时呈现错误
- 如何访问 QPainterPath 下的所有像素