PDA

View Full Version : QPainter::drawLine(): straight lines look aliased



xqrp
18th January 2012, 14:44
I'm trying to draw two single pixel lines onto a QImage with the following code:


QPainter linePainter(currentImage);
linePainter.setRenderHint(QPainter::Antialiasing, false);
linePainter.setPen(QPen(Qt::red,1));
linePainter.drawLine(xSize/2, 0, xSize/2, ySize);
linePainter.drawLine(0, ySize/2, xSize, ySize/2);

The image is displayed on a QLabel like this:


ccdDisplayLabel->setPixmap(QPixmap::fromImage(*currentImage));

However, as you can see from the attached image, somewhere along the line something bad happens. The lines should be one pixel wide and bright red, however, the vertical line looks weird. How can I fix this?

7286

wysota
18th January 2012, 18:35
Please provide a minimal compilable example reproducing the problem.

ChrisW67
18th January 2012, 21:59
If you are doing the data rendering with anti-aliasing on after drawing the red line, and it is directly adjacent to your red line, then the anti-aliasing may be overlaying the red line. Try turning off the data rendering... does the red line look right then? What happens if you render the data without anti-aliasing?

xqrp
19th January 2012, 12:22
Thanks for your replies. It seems the problem is due to Windows' remote desktop, not Qt. If I run the program while I'm in front of the actual computer, the lines appear as they're supposed to.

wysota
19th January 2012, 13:18
You probably have a loosy compression scheme (like JPEG) for your remote desktop enabled. So it's not antialiasing, it's just simplified data.