Why doesn't QAction enter into event/eventFilter?
Solved
General and Desktop
-
I've these in a subclass of
QAction
:ActionButton::ActionButton(QIcon icon, QObject *parent) : QAction(icon, "", parent){ this->installEventFilter(this); } bool ActionButton::eventFilter(QObject *watched, QEvent *event){ if(event->type() == QEvent::HoverEnter /* QEvent::Enter */){ qDebug() << "Entered"; return true; } if(event->type() == QEvent::HoverEnter /* QEvent::Leave */){ qDebug() << "Left"; return true; } return false; } bool ActionButton::event(QEvent *event){ if(event->type() == QEvent::HoverEnte /* QEvent::Enter */){ qDebug() << "Entered"; return true; } if(event->type() == QEvent::HoverLeave /* QEvent::Leave */){ qDebug() << "Left"; return true; } return false; }
BUT it doesn't print anything when mouse enters of leaves.
-
@Emon-Haque QAction is not a visual element but a QObject that handles information about the items in a QMenu, therefore, mouse events are not received. Implement the logic in a QMenu.
Since a QMenu can have several items associated each one to a QAction, then it is recommended to enable mouseTracking and use the mouseMove to determine which item is under the mouse and then compare to see if it is different from the previous item and then know if it enters or came out of the item.
-
This post is deleted!
-
@eyllanesc, posted as another question.