Although @Exa has answered this question, I want to show another solution which does not need to subclass QPushButton and is flexible in use! ( That's what I need in my project)
Step 1/2 : Overriding eventFilter.
LoginWindow.h:
// LoginWindow is where you placed your QPushButton
//(= most probably your application windows)
class LoginWindow: public QWidget
{
public:
bool eventFilter(QObject *obj, QEvent *event);
..
};
LoginWindow.cpp:
bool LoginWindow::eventFilter(QObject *obj, QEvent *event)
{
// This function repeatedly call for those QObjects
// which have installed eventFilter (Step 2)
if (obj == (QObject*)targetPushButton) {
if (event->type() == QEvent::Enter)
{
// Whatever you want to do when mouse goes over targetPushButton
}
return true;
}else {
// pass the event on to the parent class
return QWidget::eventFilter(obj, event);
}
}
Step 2/2 : Installing eventFilter on target widgets.
LoginWindow::LoginWindow()
{
...
targetPushButton->installEventFilter(this);
...
}