Skip to content

Instantly share code, notes, and snippets.

@radicaljims
Last active August 29, 2015 14:05
Show Gist options
  • Save radicaljims/cd4aa873664ef1895c5e to your computer and use it in GitHub Desktop.
Save radicaljims/cd4aa873664ef1895c5e to your computer and use it in GitHub Desktop.
class FocusInFilter : public QObject
{
Q_OBJECT
public:
FocusInFilter(QObject *parent = nullptr) : QObject(parent)
{}
signals:
void focussed();
protected:
bool eventFilter(QObject *obj, QEvent *event)
{
if(event->type() == QEvent::FocusIn)
{
emit focussed();
}
return QObject::eventFilter(obj, event);
}
private:
};
------
focus_filter = new FocusInFilter(this);
connect(focus_filter, SIGNAL(focussed()), this, SLOT(doStuff()));
auto widget_children = this->findChildren<QWidget*>();
foreach(QWidget *child, widget_children)
{
child->installEventFilter(focus_filter);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment