c++ - QT is fuzzing up my arc -
i'm trying draw beautiful arc, qt seems making pix-elated , jaggy. want smooth, , thought anti-aliasing that.
edit: using qt 4.7.4
here screen shot:
you can notice parts of red line (arc) relatively smooth, ugly looking goes around.
here self-contained paintevent. test, drop template mainwindow gui project:
void mainwindow::paintevent(qpaintevent *e) { qpainter painter(this); qbrush fillbrush = qbrush(qt::white, qt::solidpattern); qpen markpen(qt::black); qpoint centrept(this->width() / 2, this->height() / 2); int arcwidth = 8; // width of arc int radius = (this->width() / 2) - arcwidth; // radius maximum minus width of arc line int maxspeed = 80; // 80 mph max speed int maxangle = -270 * 16; // 80 mph -270, *16 drawarc int speedlimit = 40; // speed limit mph double ratio = speedlimit / static_cast<float>(maxspeed); // 80 mph max speed int anglespan_ = maxangle * ratio; int startangle_ = -135 * 16; // starting angle -135 0 mph, *16 drawarc qrect bounds(centrept.x()-radius, centrept.y()-radius, (2*radius), (2*radius)); painter.setrenderhint(qpainter::antialiasing, true); // suppose smooth out? setbackgroundrole(qpalette::base); setautofillbackground(false); painter.setbrush(fillbrush); // draw circle fillbrush = qbrush(qt::black, qt::solidpattern); painter.drawellipse(centrept, radius, radius); // draw arc markpen.setcapstyle(qt::flatcap); markpen.setjoinstyle(qt::roundjoin); markpen.setstyle(qt::solidline); markpen.setcolor(qt::red); markpen.setwidth(arcwidth); painter.setpen(markpen); fillbrush = qbrush(qt::red, qt::solidpattern); painter.setbrush(fillbrush); painter.drawarc(bounds, startangle_, anglespan_); painter.end(); }
by "relatively smooth" referring parts arc perfect line or staircase, result of anti-aliasing not visible:
at other angles it's more difficult result fine on low dpi screen, what's why these jagged smoothing:
there not can do, besides applying sharpening effect. @ end same result no antialiasing:
however can still improve black line snapping nearest grid. need use floating-point versions of qpoint
, qrect
:
qpointf centrept(this->width() / 2 + 0.5, this->height() / 2 + 0.5); ... qrectf bounds(centrept.x()-radius + 0.5, centrept.y()-radius + 0.5, (2*radius), (2*radius));
original:
with snapping:
Comments
Post a Comment