How to check an eventfilter is installed or not?



  • I want to check it in my code.



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



  • ok but is there any other way to check that



  • 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?



  • 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).



  • [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.



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



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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.