You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Wednesday, June 5th 2013, 7:07pm

Repaint QWidget using QTimer signal causes high CPU usage on Mac OS X

Hi,

I use a QTimer timeout signal to repaint QWidget and so animate a sprite composed of some QImage loaded in QWidget constructor. My app works well on Windows XP and Windows 7. My CPU usage on a PC is about nil however in Mac OS X 10.7 and 10.8 it is greater than 70%. See below my source code :

PHP Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
MySprite::MySprite(QWidget *parent) :
 QWidget(parent)
{
 timer = new QTimer(this);
 connect(timerSIGNAL(timeout()), thisSLOT(repaint()));
 currentImage 0;

 for(int i 0;i<50;i++){
 image[i] = QImage(QString(":/gui/images/pulse/image%1.png").arg(i));
 }
}

void MySprite::paintEvent QPaintEvent pe )
{
 QPainter painter(this);
 painter.drawImage(00image[currentImage]);

 currentImage = (currentImage+1) % 50;
}


I don't find how to post C code, it seems to not work.

When I comment the paintEvent function content's, it's the same.

Thank's for reading,
Florian.

This post has been edited 1 times, last edit by "flchaux" (Jun 5th 2013, 7:12pm)