0

I've got some QGraphicsObjects which are dependent of the size of the scene they are on. So my graphics object needs to know when two events occur:

  1. When it is added to the scene
  2. When it's scene is resized

The way I do it now is - create 2 signals in scene's parent: obj_create, scene_resize. And connect them to the slots of the gr.object. It seems to be not the best way. I can't find any event like addedToScene or sceneResized in the QGraphcisItem...

Thanks much.

Kolyunya
  • 5,973
  • 7
  • 46
  • 81

2 Answers2

1

I would suggest one of two possible ways: Either subclass QObject in your GraphicsItem and simply use Signal/Slots or define your own interface, lets say IResizableEvent with a resize method. In your GraphicsItem you implement the method with your resize code. When you detect a scene resize in your Scene class, just iterate over all items, cast them to the interface type and call the resize method.

0

I just needed to read the doc little bit accurately... Hope it helps someone...

QVariant        itemChange(GraphicsItemChange change, const QVariant &value)
{

    if (change == QGraphicsItem::ItemSceneHasChanged)
    {

            this->performSomeUpdates();
            QObject::connect(this->scene(),SIGNAL(sceneRectChanged(QRectF)),this,SLOT(sceneRectChanged(QRectF)));

    }

    return QGraphicsItem::itemChange(change, value);

}
Kolyunya
  • 5,973
  • 7
  • 46
  • 81