Results 1 to 20 of 22

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
    Posts
    14
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Drawing lines in QPainter takes a lot of time

    Hi,

    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;
    4.  
    5. QPainter myPainter(this);
    6. const int cst_nbLines = 5000;
    7.  
    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;
    16.  
    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 13:55.

Similar Threads

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

Tags for this Thread

Bookmarks

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.