You current design works; loading the images once, upon initialization, instead of every time the widget is painted is the right way. I was not suggesting changing that, quite the contrary.
Instead of allocating QImages on the heap, you could allocate QPixmaps directly with the MiaClasse:
class MiaClasse /* ... */ {
/* ... */
private:
}
void MiaClasse::init(){
image1.load("resources/images/image1.png");
image2.load("resources/images/image2.png");
blink = false;
}
void MiaClasse::letItBlink(){
blink = !blink;
update(); // Call this instead of QWidget::repaint()
}
painter.drawPixmap(155, 130, image1);
if(blink)
painter.drawPixmap(155, 130, image2);
}
class MiaClasse /* ... */ {
/* ... */
private:
QPixmap image1;
QPixmap image2;
}
void MiaClasse::init(){
image1.load("resources/images/image1.png");
image2.load("resources/images/image2.png");
blink = false;
}
void MiaClasse::letItBlink(){
blink = !blink;
update(); // Call this instead of QWidget::repaint()
}
void MiaClasse:: paintEvent(QPaintEvent *) {
QPainter painter(this);
painter.drawPixmap(155, 130, image1);
if(blink)
painter.drawPixmap(155, 130, image2);
}
To copy to clipboard, switch view to plain text mode
Bookmarks