Can QObject use type to filter ?
Solved
General and Desktop
-
QObject->type() == QWidget::QPushButton
bool TitleBar::eventFilter(QObject *obj, QEvent *event) { if ( obj->type() == QWidget::QPushButton && event->type() == QEvent::MouseMove ) { return true; // filter } else { return false; } // pass the event on to the parent class return QWidget::eventFilter(obj, event); }
-
Hi,
You can look at the class name::obj->metaObject()->className();
return the class Name "QPushButton"
or using a dynamic cast
QPushButton* button=qobject_cast<QPushButton*>(obj)
button == nullptr if obj is not a QPushButton
Be aware that subclass like QCommandLinkButton, in that case, are QPushButton too.