PyQt: how to handle event without inheritance

后端 未结 2 1159
别那么骄傲
别那么骄傲 2021-02-04 18:15

How can I handle mouse event without a inheritance, the usecase can be described as follows:

Suppose that I wanna let the QLabel object to handel MouseMoveEvent

2条回答
  •  醉酒成梦
    2021-02-04 18:53

    Yes you can do this, but in python2 you can't use print in your lambda, as it's a statement and not a function and does not return a value.

    Try this:

    ql = QLabel()
    def event_handler(e):
        print e.x(), e.y()
    ql.mouseMoveEvent = event_handler
    

提交回复
热议问题