Pointers 为什么QGraphicsPixmapItem没有setParent()

Pointers 为什么QGraphicsPixmapItem没有setParent(),pointers,qt5,Pointers,Qt5,QGraphicsPixmapItem不喜欢从QObject继承的其他qt对象。当其父级销毁时,它不能被销毁。使用它的唯一方法是自己删除指针吗 。。。。。。 QGraphicsPixmapItem*backGround=新的QGraphicsPixmapItem(QPixmap::fromImage(this->mat2QImage(img)),NULL); 此->场景->添加项(背景); ui.imgDisplay->setScene(场景); ui.imgDisplay->show(); .

QGraphicsPixmapItem不喜欢从QObject继承的其他qt对象。当其父级销毁时,它不能被销毁。使用它的唯一方法是自己删除指针吗

。。。。。。
QGraphicsPixmapItem*backGround=新的QGraphicsPixmapItem(QPixmap::fromImage(this->mat2QImage(img)),NULL);
此->场景->添加项(背景);
ui.imgDisplay->setScene(场景);
ui.imgDisplay->show();
......
//自行删除
删除背景;
//为什么不能将QGraphicsPixmapItem的父项设置为QGraphicscene
//当QGraphicscene销毁时,QGraphicscene下的QGraphicsPixmapItem会自动销毁。

QGraphicsPixmapItem
继承自
QGraphicsItem
,而不是
QObject

删除场景时,将删除
QgraphicsItem
。它还将删除其所有子项。因此,您不必自己删除这些项目

如果您想要基于
QObject
的图形项目,请查看
QGraphicsObject