Results 1 to 16 of 16

Thread: Drawing lines in QPainter takes a lot of time

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2016
    Qt products
    Qt4 Qt5

    Default Drawing lines in QPainter takes a lot of time


    I currently have a problem with line drawing in QPainter. I draw "only" simple 2000 lines but it takes something like 50ms for each update. My problem is all the lines continuously move to draw a nice slowly rotating graph (note : it's not just a rotate()).
    To check I run the following code only :
    Qt Code:
    1. void Widget::paintEvent(QPaintEvent *event)
    2. {
    3. QElapsedTimer chronoPainter;
    5. QPainter myPainter(this);
    6. const int cst_nbLines = 5000;
    8. chronoPainter.start();
    9. for (int i=0 ; i<cst_nbLines ; i++)
    10. {
    11. QLine myLine(i/10, i/10, i/10+300, i/10);
    12. myPainter.drawLine(myLine);
    13. }
    14. qint64 elapsed_ns = chronoPainter.nsecsElapsed();
    15. qint64 elapsed_ms = elapsed_ns/1000000L;
    17. qDebug() << "End, time to paint : " << elapsed_ms << "ms";
    18. }
    To copy to clipboard, switch view to plain text mode 

    And drawing my 2000 very simple lines takes... 50ms. Not way to have a 50FPS animation with that. Have you got an idea of how I can draw all the lines faster?
    I've tried with
    Qt Code:
    1. QVector<QLine> linesVector;
    2. for (int i=0 ; i<cst_nbLines ; i++)
    3. {
    4. linesVector.append(QLine(i/10, i/10, i/10+300, i/10));
    5. }
    6. myPainter.drawLines(linesVector);
    To copy to clipboard, switch view to plain text mode 
    but it not helps (same drawing time).

    Thank you!
    Last edited by xcxl; 4th June 2019 at 12:55.

Similar Threads

  1. Drawing Lines In Real Time (PyQt)
    By n3ziy in forum Qt Programming
    Replies: 1
    Last Post: 24th April 2016, 19:09
  2. drawing lines on a canvas and move them dynamically
    By smrati.johri in forum Newbie
    Replies: 4
    Last Post: 7th April 2016, 22:35
  3. Drawing lines on qwtpolarplot
    By jerrychan in forum Qwt
    Replies: 3
    Last Post: 12th June 2013, 10:55
  4. drawing lines using qpainter from file
    By neutrino in forum Qt Programming
    Replies: 2
    Last Post: 9th February 2013, 09:03
  5. Drawing row/column lines in QTreeWidget
    By warvimo in forum Newbie
    Replies: 0
    Last Post: 25th May 2012, 17:33

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.