【问题标题】:Drawing an arc correctly with Qt5 painter使用 Qt5 Painter 正确绘制圆弧
【发布时间】:2017-12-06 17:39:57
【问题描述】:

我正在尝试在边界矩形的边缘绘制弧线。这很重要,因为我希望它与控件一起扩展。但是,当使用boundingRect() 作为drawArc() 的参数时,这会导致边缘被剪掉。

QBrush brush(QColor("#007430"));
painter->setBrush(brush);
QPen pen;
pen.setStyle(Qt::SolidLine);
float lineWidth1 = 6.0;
pen.setWidthF(lineWidth1);
painter->setPen(pen);
painter->setRenderHint(QPainter::Antialiasing);
painter->drawArc(boundingRect(), 45*16, 270*16);

为了使其正常工作,我必须传入一个每边都比笔宽小 1/2 的矩形。 在 QT 中有没有更直接的方法可以做到这一点而无需手动计算/调整?

QRectF arcRect(0 + lineWidth1/2,
               0 + lineWidth1/2,
               boundingRect().width() - lineWidth1,
               boundingRect().height() - lineWidth1);

painter->drawArc(arcRect, 45*16, 270*16);

【问题讨论】:

    标签: c++ qt qt5 qpainter


    【解决方案1】:

    很抱歉为您带来真正的答案,不幸的是不,Qt5 中没有使用QPainter 自动缩放到绘图操作的边界框。因此,您必须在自己的代码中根据具体情况进行计算。

    从好的方面来说,这种计算并不难,通过自己计算,您一定可以完全控制整个过程。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多