How to emit a signal from a QPushButton when the mouse hovers over it?

后端 未结 5 1149
野性不改
野性不改 2021-01-05 12:52

Recently, I wanted that QPushButton can emit a signal, when the mouse pointer enters. How can I make it?

I know that QPushButton has some already defin

5条回答
  •  爱一瞬间的悲伤
    2021-01-05 13:17

    If I remember correctly, you need to enable mouse tracking for the button (Qt documentation) and override QWidget::onEnter() and QWidget::onLeave().

    You will need to create a custom button class inheriting from QPushButton. You can define signals for mouseEnter and mouseLeave in your custom class and emit them from the onEnter() and onLeave() methods that you need to override.

提交回复
热议问题