Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPainter takes much more time to draw thicker curves?

QPainter takes much more time to draw thicker curves?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qpainter
1 Posts 1 Posters 504 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CJhaC Offline
    CJhaC Offline
    CJha
    wrote on last edited by CJha
    #1

    Hi, I am drawing a sine wave (as a test) to check the time it takes to draw a curve using either QPainter::drawPolyline() or QPainter::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?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved