Ok. Here is come code that illustrates the condition. (Forgive me if it is not formatted well. I am new to this forum and fora in general).
Make a form with graphics view on it. Make one of the following classes shown in the code section below and set your view's scene to it like this: graphicsView->setScene(new QMyTestScene);
Now run and click on the scene. It makes a new ellipse that is the child of the first one. It also toggles the visiblity of the parent and thus the children. Do this about 30 times and it gets pretty slow. At about 30 or so I end up waiting like a second for it to update.
Comment out the visiblity toggling to see that adding the ellipses does not take long at all up to large numbers of ellipses.
If anyone has the heart to try this it is very interesting. Thanks!
#include <QGraphicsScene>
#include <QGraphicsItem>
#include <QGraphicsSceneMouseEvent>
{
public:
QMyTestScene(void)
{
// Make the ellipse that will be the parent of all others
theParentEllipse = addAnEllipse(0.0,0.0);
}
protected:
{
addItem(item);
return item;
}
{
// Add another ellipse at the mouse scene position
item->setParentItem(theParentEllipse);
// Toggle parent visiblity
theParentEllipse->setVisible(!theParentEllipse->isVisible());
}
};
#include <QGraphicsScene>
#include <QGraphicsItem>
#include <QGraphicsSceneMouseEvent>
class QMyTestScene : public QGraphicsScene
{
public:
QMyTestScene(void)
{
// Make the ellipse that will be the parent of all others
theParentEllipse = addAnEllipse(0.0,0.0);
}
protected:
QGraphicsEllipseItem *theParentEllipse;
QGraphicsEllipseItem *addAnEllipse(qreal x, qreal y)
{
QGraphicsEllipseItem *item = new QGraphicsEllipseItem(QRectF(x-0.1,y-0.1,2.0*0.1,2.0*0.1));
addItem(item);
return item;
}
void mousePressEvent(QGraphicsSceneMouseEvent *e)
{
// Add another ellipse at the mouse scene position
QGraphicsEllipseItem *item = addAnEllipse(e->scenePos().x(),e->scenePos().y());
item->setParentItem(theParentEllipse);
// Toggle parent visiblity
theParentEllipse->setVisible(!theParentEllipse->isVisible());
}
};
To copy to clipboard, switch view to plain text mode
Bookmarks