Results 1 to 20 of 22

Thread: Drawing lines in QPainter takes a lot of time

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drawing lines in QPainter takes a lot of time

    Maybe I repeat myself but... This is the original code :
    Qt Code:
    1. const int cst_nbLines = 5000;
    2.  
    3. for (int i=0 ; i<cst_nbLines ; i++)
    4. {
    5. QLine myLine(i/10, i/10, i/10+300, i/10);
    6. myPainter.drawLine(myLine);
    7. }
    To copy to clipboard, switch view to plain text mode 
    This is the code giving the same final result but 10 times faster :
    Qt Code:
    1. const int cst_nbLines = 5000;
    2.  
    3. for (int i=0 ; i<cst_nbLines/10 ; i++)
    4. {
    5. QLine myLine(i, i, i+300, i);
    6. myPainter.drawLine(myLine);
    7. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    315
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Drawing lines in QPainter takes a lot of time

    This is the code giving the same final result but 10 times faster :
    I think the OP understands he is drawing the same line 10 times. He misunderstood your original comment (as I did when I first read it) to say that he was executing the loop 10 times (to give 50k lines). His point is that even if these were 5000 individual lines with different coordinates, the time it takes to draw all of them is too long, no matter what method he uses.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

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

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
  •  
Qt is a trademark of The Qt Company.