Qt Hovering over a button and triggering a function?

不问归期 提交于 2019-12-20 07:21:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!