python - 派生 python 对象的深拷贝

标签 python object pyqt derived-class deep-copy

我在 python 中有一个对象,它派生自 QtGui.QGraphicsPixmapItem,具有一些基本属性和方法。在对此对象的引用上调用 deepcopy 后,当我尝试使用该副本时收到一条错误消息,提示 underlying C/C++ object has been deleted。我之前收到过这个错误,它发生在我没有在 __init__ 中调用基类的构造函数时,所以我假设这个错误是因为 QtGui.QGraphicsPixmapItem 不是被复制。

我该如何指定它?我所知道的是有一个 __deepcopy__ 方法可用于此目的。

最佳答案

QGraphicsPixmapItem 不可复制。它继承了使用 Q_DISABLE_COPY 宏声明的 QGraphicsItem,这与 QObjects 用于禁用复制的机制相同。 The documentation explains it a bit better .

关于python - 派生 python 对象的深拷贝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3705994/

相关文章:

javascript - react : Variable after keyname in map function

javascript - 无论是否可扩展,JavaScript 对象存储在哪里?

python - PyQt 访问动态创建的 Label 和 LineEdit

python - QLineEdit 更改 PlaceholderText 颜色

python - 如何加入数据框中共享相同名称的列

python - 使用 xlsxwriter,无法打开 Excel 文件。文件扩展名无效

python - 根据不同数量/长度的值/元组动态格式化字符串

python - 无法更新 python 类中的属性

button - 如何在PYQT中创建按钮点击

python - Matplotlib 表落在绘图区域之外