Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

Can't get good looking antialiasing on lines

$
0
0
Hi! I’m drawing some graphs on a QWidget using QPainter. When I enable antialiasing there is an effect more akin to a doubling of line thickness in places, and pixel jumble in other places. IMO it looks worse than no antialiasing – ref. the 4x magnified image below. Text comes out perfectly antialiased, i.e. it looks good and when zooming in you see a complex arrangement of pixels in many shades to give smooth lines with even thickness, unlike my graphs. Below is a tiny test program and an example of the output (4x mag.). I’m obviously missing something. Does anyone know what could cause antialiasing to look like that? Edit: at the very bottom I added an image with some examples of good antialiasing done by Qt, using setRenderHint( QPainter::Antialiasing ), just like I am trying to do. I’m using Qt 5.0.2 + MSVC2012 + Win7 64bit. #include <QtGui> #include <QApplication> #include <QWidget>   class AATester : public QWidget { public:   AATester( QWidget *parent = 0 ) : QWidget( parent ) {} protected:   void paintEvent( QPaintEvent *e )     {       QPainter p(this);       p.setPen( Qt::blue );       p.setRenderHint( QPainter::Antialiasing );       QPolygon polyline;       for( int x = 0; x < width(); x++ )         {           float y = sin( x * 6.28f / width() ) * height() / 2;           polyline << QPoint( x, height() / 2 + (int) y );         }       p.drawPolyline( polyline );     } };   int main( int argc, char *argv[] ) {   QApplication app( argc, argv );     AATester *a = new AATester();   a->show();     return app.exec(); }

Viewing all articles
Browse latest Browse all 13965

Trending Articles