Qt 如何在矩形周围绘制边框?

发布于 2025-01-04 23:54:04 字数 77 浏览 3 评论 0原文

我想知道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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

御守 2025-01-11 23:54:04

QPainter文档绘制矩形 说:

描边矩形的大小为[输入矩形]加上画笔宽度。

所以它是这样的:

在此处输入图像描述

QPainter's documentation for drawRect says:

A stroked rectangle has a size of [the input rectangle] plus the pen width.

So it goes like this:

enter image description here

随风而去 2025-01-11 23:54:04

我只是想添加答案并解决有关截断的问题。

可能会发生截断,因为您使用的是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文