Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why doesn't QAction enter into event/eventFilter?
Qt 6.11 is out! See what's new in the release blog

Why doesn't QAction enter into event/eventFilter?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 752 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by A Former User
    #1

    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.

    eyllanescE 1 Reply Last reply
    0
    • ? A Former User

      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.

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by eyllanesc
      #2

      @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.

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      ? 2 Replies Last reply
      1
      • eyllanescE eyllanesc

        @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.

        ? Offline
        ? Offline
        A Former User
        wrote on last edited by A Former User
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • eyllanescE eyllanesc

          @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.

          ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          @eyllanesc, posted as another question.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved