QPainterPath 增长/扩展
有没有办法获取 QPainterPath 并将其展开,例如 Selection > Photoshop 中的“增长...”(或“扩展...”)命令?
我想获取从 QGraphicsItem::shape
返回的 QPainterPath
并将其用作 QGraphicsPathItem
的基础。但我想将形状扩大给定量,例如周围 10 个像素。然后在这个展开的形状周围画一条细轮廓。
我可以通过将用于绘制QGraphicsPathItem
的QPen
的宽度设置为20(我想要的宽度* 2,因为它绘制一半在里面,一半在外面)。这给出了正确的外部形状,但有一条丑陋的粗线;没有办法(我可以看到)获得这个形状并用细线勾勒出它的轮廓。
QPainterPathStroker
类看起来很有前途,但我似乎无法让它做我想做的事。
Is there any way to take a QPainterPath
and expand it, like the Selection > Grow... (or Expand...) command in Photoshop?
I want to take the QPainterPath
returned from QGraphicsItem::shape
and use that as the basis for a QGraphicsPathItem
. But I want to expand the shape by a given amount, say 10 pixels all around. And then draw a thin outline around this expanded shape.
I can kind of do this by setting the width of the QPen
used to draw the QGraphicsPathItem
to 20 (my desired width * 2 because it draws half inside and half outside). That gives the right outside shape, but with an ugly thick line; there is no way (that I can see) to get this shape and outline it with a thin line.
The QPainterPathStroker
class looks promising, but I can't seem to get it do to what I want to.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要将 QPainterPath 增大
x
像素,您可以使用 QPainterPathStroker 使用2*x
宽笔,然后将原始内容与描边路径结合起来:但是请注意,从 Qt 4.7 开始,
united()
函数(以及类似的集合操作)将将路径转换为折线,以解决路径相交代码中的数值不稳定问题。虽然这对于绘图来说很好(两种方法之间不应该有任何明显的差异),但如果您打算保留 QPainterPath,例如允许对其进行进一步操作(您提到了 Photoshop),那么这将破坏所有贝塞尔曲线其中,这可能不是您想要的。To grow a QPainterPath by
x
pixels, you could use a QPainterPathStroker with a2*x
wide pen, then unite the original with the stroked path:Note, however, that since Qt 4.7, the
united()
function (and similar set operations) turn the paths into polylines to work around a numerical instability in the path intersection code. While this is fine for drawing (there shouldn't be any visible difference between the two methods), if you intend to keep the QPainterPath around, e.g. to allow further operations on it (you mentioned Photoshop), then this will destroy all bezier curves in it, which is probably not what you wanted.QPainterPathStroker 是正确的想法:
QPainterPath::operator+()
联合 2 个路径和
simplified()
合并子路径。这也将处理“空心”路径。QPainterPathStroker is the right idea:
QPainterPath::operator+()
unites 2 paths andsimplified()
merges sub-paths. This will also handle "hollowed" paths.