【问题标题】:Qtransform scale and width of pen set in Qpaint of qgraphicsitemqgraphicsitem的Qpaint中画笔设置的Qtransform比例和宽度
【发布时间】:2015-04-27 23:52:02
【问题描述】:

你好朋友我正在使用setTransform-方法QGraphicsItem调整和旋转QGraphicsItem,当我使用setTransform方法缩放项目时,我正在其paint-方法中绘制任何形状的QGraphicsItem QGraphicsItem 的边框也变厚了,我将名称设置为 QGraphicsItem,它也会根据比例因子变大。那么有没有什么方法可以让我在paint方法中绘制使用drawtext给出的项目和名称的边框,保持与我指定的笔宽相同。

【问题讨论】:

    标签: qt transform qgraphicsitem


    【解决方案1】:

    你需要用pen.setCosmetic(true)制作一支笔化妆,并用这支笔画边框。化妆笔的宽度不依赖于应用的变换。

    我建议使用QGraphicsSimpleTextItemQGraphicsTextItem 在场景中绘制文本。您可以通过调用textItem->setFlag(QGraphicsItem::ItemIgnoresTransformations); 来禁用文本转换。将主图形项设置为文本项的父项可能很方便,这样文本项相对于主项定位。

    请注意,在大多数情况下不需要重新实现 QGraphicsItem::paint,因为内置的 QGraphicsItem 子类可以满足各种需求。

    【讨论】:

    • 感谢 Pavel,它使用 pen.setCosmetic(true) 满足了我的边界问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-03
    • 2011-12-17
    • 2016-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多