【问题标题】:Adding extra operations to the mouseReleaseEvent向 mouseReleaseEvent 添加额外的操作
【发布时间】:2014-12-11 11:07:49
【问题描述】:

对于 QGraphicsItem(我有这个 QGraphicsItem 的一个类子类),有内置的 mouseReleaseEvent 方法,这是私有的。到目前为止,这用于使图形项平移和更新位置(内置功能)。我想添加其他功能,例如打印发布位置和其他一些语句。我应该如何做到这一点?

【问题讨论】:

    标签: python pyqt4 qgraphicsitem


    【解决方案1】:

    据我所见,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)
    

    【讨论】:

    • 我正在尝试使用 eventFilters(如果 event.type() == QtCore.QEvent.MouseMove:),直到我知道,在你的回答中提到使用 return 语句..太棒了.. . 错过了简单的事情。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-25
    • 2017-04-04
    • 2013-11-19
    • 1970-01-01
    • 2019-03-01
    • 1970-01-01
    相关资源
    最近更新 更多