【发布时间】:2014-12-11 11:07:49
【问题描述】:
对于 QGraphicsItem(我有这个 QGraphicsItem 的一个类子类),有内置的 mouseReleaseEvent 方法,这是私有的。到目前为止,这用于使图形项平移和更新位置(内置功能)。我想添加其他功能,例如打印发布位置和其他一些语句。我应该如何做到这一点?
【问题讨论】:
标签: python pyqt4 qgraphicsitem
对于 QGraphicsItem(我有这个 QGraphicsItem 的一个类子类),有内置的 mouseReleaseEvent 方法,这是私有的。到目前为止,这用于使图形项平移和更新位置(内置功能)。我想添加其他功能,例如打印发布位置和其他一些语句。我应该如何做到这一点?
【问题讨论】:
标签: python pyqt4 qgraphicsitem
据我所见,QGraphicsItem.mouseReleaseEvent() 可以在通常的庄园中被覆盖(我忘记了很多 c++ 术语,但据我从文档中看到,该方法实际上并不是私有的, 只是受保护)
class MyQGraphicsItem(QGraphicsItem):
....
def mouseReleaseEvent(self, event):
# your code here
# call the base class implementation if you want the standard behaviour to still happen
return QGraphicsItem.mouseReleaseEvent(self, event)
【讨论】: