Which part of documentation is not clear to you ?
In order to install event filter on a QLabel you need to call:
MyClass * filterObject = new MyClass(); // MyClass is a subclass of QObject
...
label->installEventFilter(filterObject);
MyClass * filterObject = new MyClass(); // MyClass is a subclass of QObject
...
QLabel * label = new QLabel();
label->installEventFilter(filterObject);
To copy to clipboard, switch view to plain text mode
After that you will be able to catch all the events that goes to label object by reimplementing virtual bool eventFilter( QObject * obj, QEvent * ev ) in filterObject class:
{
if (obj == label) {
//... test if the event is MousePress and do something with it
} else {
// pass it to the parent class
return QObject::eventFilter(obj, event
);
}
}
bool MyClass::eventFilter(QObject *obj, QEvent *event)
{
if (obj == label) {
//... test if the event is MousePress and do something with it
} else {
// pass it to the parent class
return QObject::eventFilter(obj, event);
}
}
To copy to clipboard, switch view to plain text mode
I've almost copied the example from docs.
Bookmarks