gpt4 book ai didi

qt - QPainterPath 增长/扩展

转载 作者:行者123 更新时间:2023-12-03 01:57:42 25 4
gpt4 key购买 nike

有什么方法可以获取 QPainterPath 并将其展开,就像 Photoshop 中的“选择”>“增长...”(或“展开...”)命令一样?

我想获取从 QGraphicsItem::shape 返回的 QPainterPath 并将其用作 QGraphicsPathItem 的基础。但我想将形状扩大给定量,例如周围 10 个像素。然后在这个展开的形状周围画一条细轮廓。

我可以通过将用于绘制QGraphicsPathItemQPen的宽度设置为20(我想要的宽度* 2)来实现这一点。因为它一半画在里面,一半画在外面)。这给出了正确的外部形状,但有一条难看的粗线;没有办法(我可以看到)获得这个形状并用细线勾勒出它的轮廓。

QPainterPathStroker 类看起来很有前途,但我似乎无法让它实现我想要的功能。

最佳答案

要将 QPainterPath 增大 x 像素,您可以使用 QPainterPathStroker使用 2*x 宽笔,然后将原始内容与描边路径结合起来:

QPainterPath grow( const QPainterPath & pp, int amount ) {
QPainterPathStroker stroker;
stroker.setWidth( 2 * amount );
const QPainterPath stroked = stroker.createStroke( pp );
return stroked.united( pp );
}

但请注意,自 Qt 4.7 起,united() function (以及类似的集合操作)将路径转换为折线,以解决路径相交代码中的数值不稳定问题。虽然这对于绘图来说很好(两种方法之间不应该有任何明显的区别),但如果您打算保留 QPainterPath,例如允许对其进行进一步操作(您提到了 Photoshop),那么这将破坏其中的所有贝塞尔曲线,这可能不是您想要的。

关于qt - QPainterPath 增长/扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5730409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com