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