PDA

View Full Version : QGraphicsItem not repainting



eijnuhs
19th September 2008, 06:14
Hello,

I am trying to reimplement the colliding mouse example.
Everything is the same except
QMainWindow is used.
I used the timer event to set new random position on the scene.
So far so good, I can see my QGraphicsItem on the scene.
However, the problem is that is not moving..and sometimes parts of the item on the scene will start disappearing. And I can actually 'see the item moving' or moved to a new location if I keep resizing my window or I have a scene->update() command.

Anybody has any idea why ?

Thanks !

aamer4yu
19th September 2008, 06:16
Hard to say without seeing code

Also u say u are using QMainwindow,,, have u set central widget properly ? and parents of scene and items ? or may be some problem with timer ?

eijnuhs
19th September 2008, 23:44
Update to what I did..

I added


scene()->update()

in my QGraphicsItem subclass's timer event method when the item updates its position.
It solves my repainting issue but felt its a crude way, and I will look for other means to do it.

On a side note,

Does anyone know how QGraphicsScene::changed(const QList (QRectf) rect) signal works ?
What is meant by emits signal scene's content changes ? Does that include position of the QGraphicsItem ?

How is it used most commonly ?

Ask quite abit this time but I will keep you guys updated with whatever I find.

And same as before, Thanks for reading !

patrik08
20th September 2008, 09:54
Update to what I did..
I added

scene()->update()
in my QGraphicsItem subclass's timer event method when the item updates its position.
It solves my repainting issue but felt its a crude way, and I will look for other means to do it.
On a side note,
Does anyone know how QGraphicsScene::changed(const QList (QRectf) rect) signal works ?
!


i reload scene by item on this way:

i need only by move elemenst or rotate , resize (paint outside from rect() item)



/* item */
void TextLayer::sceneReload()
{
GraphicsScene *sc;
if (sc = qobject_cast<GraphicsScene *>(scene())) {
sc->clearSelection();
}
}
/* scene */
void GraphicsScene::clearSelection()
{
QGraphicsScene::clearSelection();
/* actual rect sceneRect() or view port */
update(sceneRect());
}



or i send a setVisibleArea( const QRectF area ) to scene




void GraphicsScene::setVisibleArea( const QRectF area )
{
emit MakeVisible(area); /* to GraphicsView */
}

void GraphicsView::viewDisplay( const QRectF area )
{

/* if scale to big return text no readable */
QMatrix matx = matrix();
qreal HHscaled = matx.m11();
if (HHscaled > 5.1) {
return;
}
QGraphicsView::ensureVisible(area);
}