franco.amato
18th January 2010, 05: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
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