Reputation: 23
for(int i =0; i <shapes.size(); i++) // shapes is QList<QWidget*> of QShape
{
shapes.at(i)->setShape(QShape::ellipse);
QGraphicsProxyWidget* proxyWid = graphscene->addWidget(shapes.at(i));
}
view->setScene(graphscene);// view is a QGraphicsView object.
I have the above code that i am using to place a number of Qshapes on a Graphics view scene. looking a qt4.8 ressource i found that a QGraphicsProxyWidget need to be created to bridge the scene element with the different QWidget. the code works, but i have a concern wether the implementation is correct, is the proxywid pointer correctly allocated? is it safe to use a pointer this way? i am trying to avoid any memory problem.
Thanks in advance for assisting me
Upvotes: 2
Views: 836
Reputation: 2084
It is absolutely safe to use it like this. It is exactly as mentioned in the documentation link. Qt has a parent/children hierarchy to delete dynamically allocated widgets / objects on it's own. I'm sure, the scene will delete the QGraphicsProxyWidget objects created by "addWidget()" in it's destructor.
Upvotes: 1