Qt 如何在矩形周围绘制边框?
我想知道Qt在使用QPainter的drawRect时如何做边框。原因是我试图绘制三个彼此相邻的矩形,但我很难让它们在所有笔尺寸下完美接触。
I want to know how Qt does a border when using QPainter's drawRect. The reason for this is I am trying to draw three rectangles next to each other, but I'm having trouble getting them to touch perfectly at all pen sizes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
QPainter
的文档
绘制矩形 说:
所以它是这样的:
QPainter
's documentation fordrawRect
says:So it goes like this:
我只是想添加答案并解决有关截断的问题。
可能会发生截断,因为您使用的是 QRect 而不是 QRectF。 QRectF 为您提供浮点精度。同样,您可以使用 QPen::setWidthF(qreal width) 来确保您的边框也不会被截断。
I just wanted to add to the answer and address the question about truncation.
Truncation might be happening because you are using the QRect and not QRectF. QRectF gives you floating point precision. Similarly, you can use QPen::setWidthF(qreal width) to ensure your border is not getting truncated either.