问题
What is the proper way of triggering a function if the mouse cursor hovers over a QButton?
To be more precise I have a label called statusLabel which should show message whenever I hover my mouse cursor over a button and should revert back to empty string whenever the mouse is not over it.
回答1:
You have to create your own class, derived of QPushButton (or whichever class you want to capture hover events in).
In this class, you can override QWidget::enterEvent() to detect when the mouse hovers your widget and call your function. What you can for example do is emit a custom signal that will trigger the erasing of your label.
来源:https://stackoverflow.com/questions/41101241/qt-hovering-over-a-button-and-triggering-a-function