本文介绍了Qt椭圆边框变薄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在Qt中绘制一个椭圆,并且边缘上的边框在某些地方变细.
I am trying to draw an ellipse in Qt and the border on the edges goes thin in some places.
这是代码:
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(QPen(Qt::black, 3));
painter.drawEllipse(event->rect());
有什么想法吗?预先感谢.
Any ideas? Thanks in advance.
推荐答案
在绘制带有轮廓的形状时,必须考虑笔的宽度.因此,根据您的情况,更改为:
When painting a shape with an outline, you have to factor in the width of the pen. So in your case, change to this:
// 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 ) );
这篇关于Qt椭圆边框变薄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!