Qt椭圆边框变薄了

时间:2012-06-28 07:29:46

标签: c++ qt border ellipse

我试图在Qt中画一个椭圆,边缘的边框在某些地方会变薄。

enter image description here

以下是代码:

QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(QPen(Qt::black, 3));
painter.drawEllipse(event->rect());

有什么想法吗?提前谢谢。

1 个答案:

答案 0 :(得分:4)

绘制带轮廓的形状时,必须考虑笔的宽度。所以在你的情况下,改为:

// Adjusted by 2 pixels because half your pen width is 1.5, but QRect is
// for integer types, so rounded up.
painter.drawEllipse(event->rect().adjusted( -2, -2, 2, 2 ) );