Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想知道使用 QPainter 的 drawRect 时 Qt 是如何做边框的。这样做的原因是我试图绘制三个彼此相邻的矩形,但我无法让它们在所有笔尺寸下都能完美触摸。
QPainter的文档drawRect说:
QPainter
drawRect
描边矩形的大小为[输入矩形]加上笔宽。
所以它是这样的:
我只是想补充一下答案并解决有关截断的问题。
可能会发生截断,因为您使用的是 QRect 而不是 QRectF。QRectF 为您提供浮点精度。同样,您可以使用 QPen::setWidthF(qreal width) 来确保您的边框也不会被截断。