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. How to check an eventfilter is installed or not?

How to check an eventfilter is installed or not?

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 5.5k Views
  • 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.
  • P Offline
    P Offline
    pratik041
    wrote on last edited by
    #1

    I want to check it in my code.

    Pratik Agrawal

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      You can't. There is no API for that.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pratik041
        wrote on last edited by
        #3

        ok but is there any other way to check that

        Pratik Agrawal

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          You may find something if you dig into the QObject sources. However, why don't you just keep track of it yourself? Why do you need to know this in the first place?

          1 Reply Last reply
          0
          • B Offline
            B Offline
            broadpeak
            wrote on last edited by
            #5

            What you need is reflection, but in ANSI/C++ (as I know), this is impossible. Java has kinda property.
            In "boost" ( http://www.boost.org/ ) you can do something like this with TypeTraits, but only in compile-time (and not in run-time).

            1 Reply Last reply
            0
            • P Offline
              P Offline
              pratik041
              wrote on last edited by
              #6

              [quote author="Andre" date="1322305153"]You may find something if you dig into the QObject sources. However, why don't you just keep track of it yourself? Why do you need to know this in the first place?[/quote]
              I need to know because if i am installing eventfilter for parent object then when the mouse is over child object then also parent object is receiving eventfilter. i want to detect mouse is over which object during runtime.

              Pratik Agrawal

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                Then you are using the mechanism in the wrong way.
                If you want to know over which object the mouse is, you simply install an eventfilter on the application object, listen for mouseOver events, and track the object that event was send to. No need to know about other event filters.

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  pratik041
                  wrote on last edited by
                  #8

                  Sorry, but can you please explain this by brief code.

                  Pratik Agrawal

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #9

                    @
                    class MouseOverTracker: public QObject
                    {
                    Q_OBJECT
                    public:
                    MouseOverTracker(QObject* parent = 0);
                    bool eventFilter(QObject* object, QEvent* event);

                    QWidget* currentHoverWidget() {return m_currentWidget;}

                    private:
                    QWidget* m_currentWidget;
                    }

                    MouseOverTracker::MouseOverTracker()
                    : QObject(parent), m_currentWidget(0)
                    {
                    qApp->installEventFilter(this);
                    }

                    bool MouseOverTracker::eventFilter(QObject* object, QEvent* event)
                    {
                    if (!event || !object)
                    return false;

                    if (event->type() == QEvent::Enter) {
                    m_currentWidget = qobject_cast<QWidget*>(sender);
                    } else if (event->type() == QEvent::Leave) {
                    if (m_currentWidget == object)
                    m_currentWidget = 0;
                    }

                    return false;
                    }

                    @

                    Note: not tested, directly typed into forum editor.

                    You should be able to get your current widget by creating an instance of the class, and calling currentWidget() on it.

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      pratik041
                      wrote on last edited by
                      #10

                      [quote author="Andre" date="1322395645"]@
                      class MouseOverTracker: public QObject
                      {
                      Q_OBJECT
                      public:
                      MouseOverTracker(QObject* parent = 0);
                      bool eventFilter(QObject* object, QEvent* event);

                      QWidget* currentHoverWidget() {return m_currentWidget;}

                      private:
                      QWidget* m_currentWidget;
                      }

                      MouseOverTracker::MouseOverTracker()
                      : QObject(parent), m_currentWidget(0)
                      {
                      qApp->installEventFilter(this);
                      }

                      bool MouseOverTracker::eventFilter(QObject* object, QEvent* event)
                      {
                      if (!event || !object)
                      return false;

                      if (event->type() == QEvent::Enter) {
                      m_currentWidget = qobject_cast<QWidget*>(sender);
                      } else if (event->type() == QEvent::Leave) {
                      if (m_currentWidget == object)
                      m_currentWidget = 0;
                      }

                      return false;
                      }

                      @

                      Note: not tested, directly typed into forum editor.

                      You should be able to get your current widget by creating an instance of the class, and calling currentWidget() on it.[/quote]

                      thank you

                      Pratik Agrawal

                      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