是否有任何方法可以进行QPainterPath扩展,例如Photoshop中的Selection> Grow ...(或Expand ...)命令?
我想QPainterPath从返回中获取QGraphicsItem::shape并使用它作为a的基础QGraphicsPathItem.但我希望将形状扩展一个给定的数量,比如说10个像素.然后围绕这个扩展的形状绘制一个薄的轮廓.
我可以通过设置用于绘制20的宽度(我想要的宽度*2,因为它绘制一半内部和一半外部)来做到这一点.这给了正确的外形,但有一条难看的粗线条; 没有办法(我可以看到)获得这个形状并用细线勾勒出它.QPenQGraphicsPathItem
这QPainterPathStroker堂课看起来很有希望,但我似乎无法做到我想要的.
QPainterPathStroker是正确的想法:
QPainterPathStroker stroker;
stroker.setWidth(20);
stroker.setJoinStyle(Qt::MiterJoin); // and other adjustments you need
QPainterPath newpath = (stroker.createStroke(oldPath) + oldPath).simplified();
Run Code Online (Sandbox Code Playgroud)
QPainterPath::operator+()simplified()合并2条路径并合并子路径。这也将处理“空心”路径。
要按x像素增长QPainterPath ,可以使用带有宽笔的QPainterPathStroker2*x,然后将原始内容与描边路径结合使用:
QPainterPath grow( const QPainterPath & pp, int amount ) {
QPainterPathStroker stroker;
stroker.setWidth( 2 * amount );
const QPainterPath stroked = stroker.createStroke( pp );
return stroked.united( pp );
}
Run Code Online (Sandbox Code Playgroud)
但请注意,自Qt 4.7起,united()函数(和类似的集合运算)将路径转换为折线,以解决路径交叉代码中的数值不稳定问题.虽然这对于绘图来说很好(两种方法之间不应该有任何明显的区别),如果你打算保持QPainterPath,例如允许对它进行进一步操作(你提到过Photoshop),那么这将破坏所有bezier曲线在它,这可能不是你想要的.
| 归档时间: |
|
| 查看次数: |
3239 次 |
| 最近记录: |