meazza
23rd June 2011, 12:24
Hello fellow programmers.
I have a question regarding my paintEvent in my class which is derived from QWidget. And what I am asking here is why does this paintEvent take up 70-80 % of my cpu when I add this object to a QGraphicsScene and move it around.
I know I can get a significant boost in performance by setting the QGraphcsItem::DeviceCoordinateCache flag as cacheMode but I am just curios why my paintEvent is so heavy on the CPU and if I can somehow improve it.
PS. The pixmap that I am using is only loading the first time I create the object since I store it in the QPixmapCache and use it from there.
void CDITachometer::paintEvent(QPaintEvent *)
{
/* Min rotate(-93)
* Max rotate(162)
* Mid rotate(36)
*/
QPainter boolPainter(this);
boolPainter.setRenderHint(QPainter::SmoothPixmapTr ansform);
QPixmap pixmap = *QPixmapCache::find(accessibleName());
boolPainter.drawPixmap(0, 0, pixmap.scaled(size().width(), size().height(),
Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
QTransform transform2;
transform2.translate(size().width()/2, size().height()/2);
transform2.rotate(m_rotation);
transform2.translate(-size().width()/2, -size().height()/2);
boolPainter.setTransform(transform2);
pixmap = *QPixmapCache::find(accessibleName().append("1"));
boolPainter.drawPixmap(0, 0, pixmap.scaled(size().width(), size().height(),
Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
}
Thanks in advance and I appritiate all advice and comments
I have a question regarding my paintEvent in my class which is derived from QWidget. And what I am asking here is why does this paintEvent take up 70-80 % of my cpu when I add this object to a QGraphicsScene and move it around.
I know I can get a significant boost in performance by setting the QGraphcsItem::DeviceCoordinateCache flag as cacheMode but I am just curios why my paintEvent is so heavy on the CPU and if I can somehow improve it.
PS. The pixmap that I am using is only loading the first time I create the object since I store it in the QPixmapCache and use it from there.
void CDITachometer::paintEvent(QPaintEvent *)
{
/* Min rotate(-93)
* Max rotate(162)
* Mid rotate(36)
*/
QPainter boolPainter(this);
boolPainter.setRenderHint(QPainter::SmoothPixmapTr ansform);
QPixmap pixmap = *QPixmapCache::find(accessibleName());
boolPainter.drawPixmap(0, 0, pixmap.scaled(size().width(), size().height(),
Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
QTransform transform2;
transform2.translate(size().width()/2, size().height()/2);
transform2.rotate(m_rotation);
transform2.translate(-size().width()/2, -size().height()/2);
boolPainter.setTransform(transform2);
pixmap = *QPixmapCache::find(accessibleName().append("1"));
boolPainter.drawPixmap(0, 0, pixmap.scaled(size().width(), size().height(),
Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
}
Thanks in advance and I appritiate all advice and comments