Qt Ellipse Border Thins Out

ぐ巨炮叔叔 提交于 2019-12-21 23:50:37

问题


I am trying to draw an ellipse in Qt and the border on the edges goes thin in some places.

Here is the code:

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

Any ideas? Thanks in advance.


回答1:


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 ) );


来源:https://stackoverflow.com/questions/11239964/qt-ellipse-border-thins-out

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!