PDA

View Full Version : Strange behaviour with QPen



franco.amato
18th January 2010, 06:11
Hi to all,
I have to draw some lines in the paint event of an widget.
I set a pen with width = 1 but the real width of the pen is visibility bigger than 1 pixel and the width method
return 1 as value...odd

Here some code:



QPixmap temp = QPixmap( w, h ); // I draw on a pixel to cache

QPainter p( &temp );
p.setRenderHint( QPainter::Antialiasing, true );
p.fillRect( temp.rect(), Qt::lightGray );

// temporal line
QPen pen(Qt::black, 1); //<---- 1 pixel wide
pen.setStyle(Qt::SolidLine);
p.setPen(pen);
p.drawLine(0, 20, w, 20); //width of the line bigger than 1 pixel
qDebug() << "Pen width: " << pen.width(); // returns 1

Any idea?

Best

boudie
18th January 2010, 11:29
What does it look like when you don't use QPainter::Antialiasing?

And what happens when you set pen width to zero: a "cosmetic pen"? That one should always draw 1 pixel wide.

franco.amato
18th January 2010, 16:30
What does it look like when you don't use QPainter::Antialiasing?

And what happens when you set pen width to zero: a "cosmetic pen"? That one should always draw 1 pixel wide.

I removed the Antialiasing flag and seems solved the problem but why???

wagmare
19th January 2010, 06:19
your painted line will have some strange looking like a small saw tooth wave normally rather than straight .. try to draw a cross line u can see it clearly .. antialiasing is like coating or filling the scramble space ..
see the link
http://doc.trolltech.com/4.3/coordsys.html#aliased-painting

franco.amato
19th January 2010, 06:51
your painted line will have some strange looking like a small saw tooth wave normally rather than straight .. try to draw a cross line u can see it clearly .. antialiasing is like coating or filling the scramble space ..
see the link
http://doc.trolltech.com/4.3/coordsys.html#aliased-painting

Thank you for your explanation. This is why the width of my line is bigger than 1 pixel