scene->addItem() moans about QTimer ???
I want to move an QGraphicsItem gi in a scene being displayed. I use
Code:
scene->removeItem(gi);
gi->setPos(x, y);
scene->addItem(gi);
At that point I get a warning
and the view doesn't change. The warning totally foxes me. I have several threads in my program but gdb confirms all the basic GUI thread is active at this point. I don't want a timer, I want the view updated.
What is going on?
At first I had no removeItem addItem calls but that was gave the same warning.
Thanks for any suggestions,
Enno
Re: scene->addItem() moans about QTimer ???
Use a tracer or debugger to step trough the code.
I don't think it is possible to tell where the error is with the information you have given.
By the way, why do you remove an object from the scene in order to move its position?
Re: scene->addItem() moans about QTimer ???
Thanks. Will do some more debugging.
Remove/add back only to see whether that made a difference. It didn't.
Enno
Re: scene->addItem() moans about QTimer ???
Problem appears similar to what happens after calling update() from inside a paintEvent, against which the docs explicitly warn.
I am calling update() from inside a mousePressEvent() and can't do much else because it is the mouse press that should triggers moving a QGraphicsRectItem to that position. The rect->setPos(x,y) causes the QTimer warning.
After that a call view->update() does trigger a paintEvent but the rect does not get drawn at all.
It is almost as if the view does not notice the scene change and hence skips repainting.
Is this related to the new GraphicsItemFlags introduced in Qt 4.6. Before that things were working fine.
I am still puzzled.
Enno
Re: scene->addItem() moans about QTimer ???
You rarely need to call update() manually. If you just change the position of the item, update() is not required, setPos() will suffice. Just make sure it is all done from the GUI thread.
Re: scene->addItem() moans about QTimer ???
You put your finger on the sore spot: new scene in non-GUI thread. The docs warned me, you warned me but I did.
Thanks.