PDA

View Full Version : line draw issue



prashantbasvat
28th June 2016, 13:00
i have written simple application to draw a line between points using qpainter.but when i saw drawn line on widget it appears to be some broken line , instead of straight line between points. how to solved this issue.


QPainter painter(this);
painter.setRenderHint(QPainter::SmoothPixmapTransf orm,true);
painter.fillRect(10 , 10, 300, 200, Qt::black);
painter.setPen(QPen(Qt::green, 1));
drawPath.moveTo(20,100);
drawPath.lineTo(119,100);
drawPath.moveTo(20,100);
drawPath.lineTo(20,11);
drawPath.moveTo(25,98);
drawPath.lineTo(27,80);
painter.drawPath(drawPath);

Alundra
30th June 2016, 03:29
Qt surely uses Bresenham algorithm to render the line : https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
Maybe increase the line width ? Maybe try this too : painter.setRenderHint(QPainter::Antialiasing, true);
I see also QPainter::HighQualityAntialiasing in the doc, can be tried.