Summary
I use qt 4.8.7 under SUSE 64 bits
I have 2 QGraphicsItem with different refreshment rates. But when I call "update()" on one of them, "paint()" is called on both of them. So the real refreshment for both items rate is the highest common factor of the two refreshments.
I would like to have independent calls to paint() methods... I have no idea where does this issue come from and how to solve it (I tried to call QGraphicsItem::update(QRectF(//item_dimensions//))" instead of QGraphicsItem::update() but the problem is the same)
Simplified code
toto.hpp
class Toto : public QObject, QGraphicsItem
{
Q_OBJECT
public:
Toto(QString name)
{
m_name = name;
}
void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget* = NULL)
{
QTextStream(stdout) << "paint : " << m_name << endl;
//other stuff
}
public slots:
void updateSlot()
{
QTextStream(stdout) << "\nupdate : " << m_name << endl;
QGraphicsItem::update();
}
private:
QString m_name;
}
main.cpp
Toto1 = new Toto("toto_1");
Toto2 = new Toto("toto_2");
QTimer *timer1 = new QTimer(500);
QTimer *timer2 = new QTimer(2000);
connect(timer1, SIGNAL(timeout()), toto1, SLOT(updateSlot()));
connect(timer2, SIGNAL(timeout()), toto2, SLOT(updateSlot()));
timer1->start();
timer2->start();
Expected output:
toto_1 update
toto_1 paint
toto_1 update
toto_1 paint
toto_1 update
toto_1 paint
toto_1 update
toto_1 paint
toto_2 update
toto_2 paint
toto_1 updated every 500ms, toto_2 updated every 2000ms
What I get:
toto_1 update
toto_1 paint
toto_2 paint
toto_1 update
toto_1 paint
toto_2 paint
toto_1 update
toto_1 paint
toto_2 paint
toto_1 update
toto_1 paint
toto_2 paint
toto_2 update
toto_1 paint
toto_2 paint
toto_1 and toto_2 both updated every 500ms
Thank you for your help !