QGraphicsPixmapItem不像其他继承自QObject的qt对象。当它的父对象销毁时,它不能被销毁。使用它的唯一方法是自己删除指针吗?
......
QGraphicsPixmapItem * backGround = new QGraphicsPixmapItem(QPixmap::fromImage(this->mat2QImage(img)), NULL);
this->scene->addItem(backGround);
ui.imgDisplay->setScene(scene);
ui.imgDisplay->show();
......
// delete by myself
delete backGround;
// why can not I set the parent of the QGraphicsPixmapItem to QGraphicsScene
// when QGraphicsScene destroy, QGraphicsPixmapItem under QGraphicsScene automatically destroy.发布于 2019-08-02 22:53:25
QGraphicsPixmapItem继承自QGraphicsItem,而不是QObject。
删除场景时,将删除QgraphicsItem。它还将删除其所有子对象。因此,您不必删除自己的项目。
如果你想要一个基于QObject的图形项目,你应该看看QGraphicsObject。
https://stackoverflow.com/questions/57328328
复制相似问题