QPainter takes much more time to draw thicker curves?
Unsolved
General and Desktop
-
Hi, I am drawing a sine wave (as a test) to check the time it takes to draw a curve using either
QPainter::drawPolyline()
orQPainter::drawPath()
. In either case, if I set the pen width to more than 1, then the time it takes to draw the sine wave increases by more than 10 times.Widget::Widget(QWidget* parent) : QWidget(parent) { setAutoFillBackground(true); setAttribute(Qt::WA_NoSystemBackground, true); for(qsizetype ii = 0; ii < 1000000; ++ii) sineWave << (1.0 + sin(2 * M_PI * 3 * ii / 1000000)); } void Widget::paintEvent(QPaintEvent* evt) { QPainter painter(this); painter.fillRect(rect(), QColor(Qt::white)); painter.setRenderHint(QPainter::Antialiasing); QPen pen; pen.setWidthF(2); // setting pen width painter.setPen(pen); QElapsedTimer timer; timer.start(); qDebug() << "-> Paint Event\tPen Width:" << pen.widthF() << "\tWidget WxH:" << width() << "x" << height(); QList<QPointF> pixPoints; for(qsizetype ii = 0; ii < sineWave.length(); ++ii) { double yPos = height() * (sineWave[ii] / 2.0); double xPos = width() * (ii / 1000000.0); pixPoints << QPointF(xPos, yPos); } qDebug() << "--> 1: Time [ms]:" << (timer.nsecsElapsed() / 1000000.0); painter.drawPolyline(pixPoints); qDebug() << "--> 2: Time [ms]:" << (timer.nsecsElapsed() / 1000000.0); }
The results I get:
-> Paint Event Pen Width: 2 Widget WxH: 692 x 465 --> 1: Time [ms]: 101.754 --> 2: Time [ms]: 5768.86 -> Paint Event Pen Width: 2 Widget WxH: 722 x 494 --> 1: Time [ms]: 109.352 --> 2: Time [ms]: 5887.08 -> Paint Event Pen Width: 1 Widget WxH: 720 x 515 --> 1: Time [ms]: 114.286 --> 2: Time [ms]: 253.72 -> Paint Event Pen Width: 1 Widget WxH: 741 x 535 --> 1: Time [ms]: 105.882 --> 2: Time [ms]: 233.165
Is there any way I can reduce this time gap?