PDA

View Full Version : High cpu usage in custom QItemDelegate::paint



rsilva
17th May 2011, 06:06
I'm using a QItemDelegate to draw controls in a QListView.
But, I've found that makes a high cpu usage 80~100% in my computer.

I think it's happens when I use the buttons, if I have only the progress bar and text there's no high cpu usage.

I'm using the paint to simulate 6 buttons with icons, a progress and one text in each item.

(As my code is a big file I've send it as a attachment.)

Here, my ItemDelegate subclass (only .cpp):
6428

for the data for the indexes, I'm using this class:


#ifndef DOWNLOADITEM_H
#define DOWNLOADITEM_H

#include <QObject>
#include <QHash>
#include <QVariant>

class DownloadItem : public QObject
{
Q_OBJECT
public:
explicit DownloadItem(QObject* parent = 0);
virtual ~DownloadItem();

QVariant data(int a) const { return m_data.value(a); }
void setData(int a, QVariant b) { m_data[a] = b; }

private:
QHash<int, QVariant> m_data;
};

#endif // DOWNLOADITEM_H


And if this helps, here a screenshot of the window:
6427

Any ideas to fix it ?
Is that QHash slow for using data and drawing ?

wysota
17th May 2011, 22:52
Calling setData() from within the drawing code is definitely a bad idea. This causes a redraw of the item and your application does nothing but redraws the items over and over again. The model is const in paint() for a reason.