PDA

View Full Version : QGraphicsScene update?



Gurdt
16th April 2009, 10:12
Hi,

In a project I'm currently working on, I've encountered a problem, I'll describe it the best I can:

There is a QGraphicsView whit a QGraphicsScene in it, wherein I'm adding some QGraphicItems, that is working fine, even when I add a QWidget (resulting in a QGraphicsProxyWidget) it shows up perfectly in de scene (the QWidget I'm adding is a second QGraphicsView).

The problem however occurs when I try to move or scale te QGraphicsProxyWidget, it seems that the shape() or the boundingRect() isn't updating or something.
I tried some things like update(), setGeometryChange() etc, but nothing is working...

Can someone help me?
Thanks
Gurdt

wysota
16th April 2009, 10:31
As far as I know embedding a graphics view inside graphics view doesn't work well. I don't know whether Qt4.5 introduced improvements in the matter but previous versions had problems with such configuration. Moving() a widget item won't change its boundingRect() or shape() though and that's ok. Can we see the code you are using?

Gurdt
16th April 2009, 11:02
class Bord : public QGraphicsView
{
Q_OBJECT
...
private:
QGraphicsScene* m_bordScene;
...
}

...

//interfaceScene is a QGraphicsScene
QGraphicsProxyWidget *m_bord = interfaceScene->addWidget( new Bord());
m_bord->moveBy(40, 100);
so the QGraphicsView is added into a QGraphicsScene, resulting in a QGraphicsProxyWidget.

Here is a screenshot of the interfaceScene BEFORE moving: http://home.scarlet.be/gertnelissen/problem_beforeMoving.jpg
Here is a screenshot AFTER: http://home.scarlet.be/gertnelissen/problem_afterMoving.jpg

information: the white rectangle is the size of a Bord (QGraphicsScene), there are some blocks in it (it's a puzzle), these blocks are, as you can see, not drawed well after moving

zgulser
16th April 2009, 12:08
Hi,

you can try setPos() to move your item.

Gurdt
16th April 2009, 12:27
Sorry it has no effect, what is pretty obvious becouse moveBy is built on setPos I guess ;)

zgulser
16th April 2009, 12:35
Hi,

I'am ok with that but sometimes it could be helpful to try different methods. If you didn't try, have it your way:)

by the way, did you add your item to the scene right? I see addWidget there maybe you should replace it with addItem?

Gurdt
16th April 2009, 12:49
been there done that :(
I've tried all manners to update a scene, and all manners to add a widget into a scene...

Maybe it's not meant to add a QGraphicsView in another?

(I've tried other QGraphicsProxyWidget and then it works just fine, the problem seems to occur only when I try to add another QGraphicsView)

zgulser
16th April 2009, 12:57
Great than:)

Gurdt
16th April 2009, 14:23
Sorry if you misunderstood me, but I still haven't find any solution,
I really need to add a QGraphicsView into another QGraphicsView, I still get the error...

zgulser
16th April 2009, 14:47
Ok,

I think you know one scene can be observed by several views but your style seems really wierd (adding another QGraphicsView inside the QGraphicsScene which inside another QGraphicsView).

Hımm, you may try to add a new scene in to your QGraphicsProxyWidget.

You can also send me your source code if possible. I can check it out.

Gurdt
16th April 2009, 14:54
The reason why I'm adding a view to another scene is because my bord (means puzzle) is a class on its own, accidentally using a scene+view itself.

My interface is a large scene/view, and graphicsitems and buttons are added to that scene. Just like that, I'm adding a Bord (puzzle) class, which is a GraphicsView itself.

Since the puzzle uses drag and drop, I can't see any other way to implement it.

wysota
17th April 2009, 09:03
The reason why I'm adding a view to another scene is because my bord (means puzzle) is a class on its own, accidentally using a scene+view itself.
You should be able to rewrite it easily so that the internal scene is replaced by a graphics item with all the functionality retained and the scene items become child items of the "board" item.