PDA

View Full Version : QPainter::drawRect in Qt4.5 is much slower than that in Qt4.3



bgcrwf
15th April 2010, 12:44
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();
}

borisbn
15th April 2010, 14:18
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:


213 ms
160 ms
172 ms
162 ms
162 ms
162 ms
162 ms
179 ms
162 ms
175 ms
161 ms

P.S. my picture is 80x80 JPEG



void tst::paintEvent( QPaintEvent * )
{
QTime t;
t.start();
// You can change the file name if you need
QPixmap pixmap( "d:\\Pictures\\shrek_3_-_cat_avatar__80.jpg" );
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();
qDebug() << t.elapsed();
}

bgcrwf
15th April 2010, 15:04
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.:o

borisbn
15th April 2010, 15:16
ok, I changed QPixmap to QBitmap, and had this results:


571
493
498
498
497
500
500
497
497
500

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

bgcrwf
15th April 2010, 15:44
Hi,

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

Thanks a lot.

bgcrwf
15th April 2010, 16:29
I've tested the peformace of Qt4.5 in windows environment.
It seemed that the problem only happened in Linux X11.
:(

pherthyl
15th April 2010, 20:56
Please report: http://bugreports.qt.nokia.com