2 Attachment(s)
High cpu usage in custom QItemDelegate::paint
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):
Attachment 6428
for the data for the indexes, I'm using this class:
Code:
#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:
Attachment 6427
Any ideas to fix it ?
Is that QHash slow for using data and drawing ?
Re: High cpu usage in custom QItemDelegate::paint
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.