Results 1 to 7 of 7

Thread: QPainter::drawRect in Qt4.5 is much slower than that in Qt4.3

  1. #1
    Join Date
    Apr 2010
    Posts
    4
    Qt products
    Qt4

    Default QPainter::drawRect in Qt4.5 is much slower than that in Qt4.3

    As title. I wrote a program to test the peformance of QPainter::drawRect.
    This program draws 10 rectangles 100 times.
    In Qt4.5, the elapsed time is over 1 minute.
    But in Qt4.3, the elapsed time is less than 1 second.
    By the way, I executed it in Linux X11.
    What should I do to fix the problem in Qt4.5?
    Thanks a lot.

    ======================================
    class PainterWidget : public QWidget
    {
    protected:
    void paintEvent(QPaintEvent *);
    };

    void PainterWidget :: paintEvent(QPaintEvent *)
    {
    // You can change the file name if you need
    QBitmap pixmap("xxx.pbm");
    QBrush brush(pixmap);
    brush.setColor(Qt::red);

    QPainter painter(this);
    painter.end();

    painter.begin(this);
    painter.setBrush(brush);
    QRect rect;
    for (int j=0; j<100; j++) {
    for (int i=0; i<10; i++) {
    rect.setRect(i*100, 0, 100, 1000);
    painter.drawRect(rect);
    }
    }
    painter.end();
    }

    int main(int argc, char* argv[])
    {
    QApplication app(argc, argv);

    PainterWidget window;
    window.resize(1000, 1000);
    window.show();

    return app.exec();
    }
    Last edited by bgcrwf; 15th April 2010 at 11:51.

  2. #2
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPainter::drawRect in Qt4.5 is much slower than that in Qt4.3

    I think, that I wouldn't help you yet, but...
    I tried your code with Qt 4.6.2 at Windows 7 and Visual Studio 2008 ( all of them are not your case )
    in Release version of program i had:
    Qt Code:
    1. 213 ms
    2. 160 ms
    3. 172 ms
    4. 162 ms
    5. 162 ms
    6. 162 ms
    7. 162 ms
    8. 179 ms
    9. 162 ms
    10. 175 ms
    11. 161 ms
    To copy to clipboard, switch view to plain text mode 
    P.S. my picture is 80x80 JPEG

    Qt Code:
    1. void tst::paintEvent( QPaintEvent * )
    2. {
    3. QTime t;
    4. t.start();
    5. // You can change the file name if you need
    6. QPixmap pixmap( "d:\\Pictures\\shrek_3_-_cat_avatar__80.jpg" );
    7. QBrush brush( pixmap );
    8. brush.setColor( Qt::red );
    9.  
    10. QPainter painter( this );
    11. //painter.end();
    12.  
    13. //painter.begin(this);
    14. painter.setBrush( brush );
    15. QRect rect;
    16. for (int j=0; j<100; j++) {
    17. for (int i=0; i<10; i++) {
    18. rect.setRect( i*100, 0, 100, 1000 );
    19. painter.drawRect( rect );
    20. }
    21. }
    22. painter.end();
    23. qDebug() << t.elapsed();
    24. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2010
    Posts
    4
    Qt products
    Qt4

    Default Re: QPainter::drawRect in Qt4.5 is much slower than that in Qt4.3

    Dear borisbn,

    In line 6 of your program, the QPixmap must be replaced with QBitmap to reproduce the program.
    That is because I want to use the bitmap as a mask of the brush.
    You can choose a monochrome picture to build the bitmap.

    Actually, when I use QPixmap, the drawing performance is excellent (the same as yours).
    But when I use QBitmap, the performance degrades a lot.
    I think that it should be related to transparent drawing.
    By the way, I can reproduce the problem in Qt4.6, too.

    Thanks.

  4. #4
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPainter::drawRect in Qt4.5 is much slower than that in Qt4.3

    ok, I changed QPixmap to QBitmap, and had this results:
    Qt Code:
    1. 571
    2. 493
    3. 498
    4. 498
    5. 497
    6. 500
    7. 500
    8. 497
    9. 497
    10. 500
    To copy to clipboard, switch view to plain text mode 
    image was not clearly showed, time increased by 3 times, but it still not a 1 minute
    can you attach your bitmap file xxx.pbm

  5. #5
    Join Date
    Apr 2010
    Posts
    4
    Qt products
    Qt4

    Default Re: QPainter::drawRect in Qt4.5 is much slower than that in Qt4.3

    Hi,

    I am glad to upload the image file.
    It's in the attachments.

    Thanks a lot.
    Attached Images Attached Images

  6. #6
    Join Date
    Apr 2010
    Posts
    4
    Qt products
    Qt4

    Default Re: QPainter::drawRect in Qt4.5 is much slower than that in Qt4.3

    I've tested the peformace of Qt4.5 in windows environment.
    It seemed that the problem only happened in Linux X11.

  7. #7
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPainter::drawRect in Qt4.5 is much slower than that in Qt4.3


Similar Threads

  1. Qt/mingw a lot slower than borland builder 6.0?
    By qt_gotcha in forum Qt Programming
    Replies: 2
    Last Post: 23rd February 2010, 12:11
  2. why Qt4 is so slower than Qt3 ?
    By xuyaojun1980 in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 11th February 2009, 18:32
  3. Which is faster, drawRect(..) Or drawPath(..) ?
    By nileshsince1980 in forum Qt Programming
    Replies: 1
    Last Post: 18th November 2008, 08:26
  4. problem about drawRect
    By vql in forum Qt Programming
    Replies: 4
    Last Post: 29th April 2008, 01:07
  5. drawRect inside paintGL()
    By mickey in forum Newbie
    Replies: 16
    Last Post: 18th April 2006, 01:12

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.