I am trying to implement a mouseover effect in Qt, but I don’t know how to use the event handlers. I have created a simple Qt Widget Application with a pushButton. I am able to bind an event handler to the MainWindow like so:
MainWindow::enterEvent(QEvent *event)
{
ui->pushButton_3->setGraphicsEffect(effect);
}
This works, the graphicsEffect is applied to the pushButton. But I don’t understand how to bind the event handler to a single QObject. As far as I know is it not possible to use signals, because they only support click events and no mouseover events.
I am pretty new to Qt and I was not able to find any information I could understand.
Can anyone explain to me how to bind an event handler to a single QObject?
Thanks in advance.
I figured it out, in another way, by using the ‘Promote to …’ option in the QtCreator.
As also explained here: http://sector.ynet.sk/qt4-tutorial/customing-widgets.html
I added a class ‘MyPushButton”:
mypushbutton.h
mypushbutton.cpp
and then I right clicked my QPushButton in the editor and I selected ‘Promote to …’ and I added MyPushButton as ‘Promoted class name’.
It works like a charm and is very easy to expand or customize as it works with any event.