16 #include <QApplication>
29 if (event->type() != QEvent::KeyPress)
30 return QObject::eventFilter(obj, event);
32 auto* keyEvent =
dynamic_cast<QKeyEvent*
>(event);
33 if (keyEvent->key() == Qt::Key_Space)
35 return QObject::eventFilter(obj, event);
49 obj->installEventFilter(p);
54 if (
auto* spinBox = qobject_cast<QAbstractSpinBox*>(obj)) {
55 if (event->type() == QEvent::Wheel) {
56 if (spinBox->focusPolicy() == Qt::WheelFocus) {
63 if (event->type() == QEvent::FocusIn)
64 spinBox->setFocusPolicy(Qt::WheelFocus);
65 else if (event->type() == QEvent::FocusOut)
66 spinBox->setFocusPolicy(Qt::StrongFocus);
67 }
else if (qobject_cast<QComboBox*>(obj)) {
68 if (event->type() == QEvent::Wheel) {
75 return QObject::eventFilter(obj, event);
83 if (event->type() == QEvent::KeyPress) {
84 auto* keyEvent =
dynamic_cast<QKeyEvent*
>(event);
85 if (keyEvent->key() == Qt::Key_Delete)
88 return QObject::eventFilter(dist, event);
100 if (event->type() == QEvent::FocusOut)
103 return QObject::eventFilter(obj, event);
110 , m_shortcode(std::move(shortcode))
118 if (event->type() == QEvent::KeyPress) {
119 auto* keyEvent =
dynamic_cast<QKeyEvent*
>(event);
147 if (event->type() != QEvent::MouseButtonPress)
149 return QObject::eventFilter(obj, event);
150 auto* mouseEvent =
dynamic_cast<QMouseEvent*
>(event);
151 if (mouseEvent->button() == Qt::RightButton) {
167 if (parent->focusProxy())
168 parent->focusProxy()->installEventFilter(
this);
173 if (event->type() == QEvent::KeyPress) {
174 auto* keyEvent =
dynamic_cast<QKeyEvent*
>(event);
175 if (keyEvent->key() == Qt::Key_Tab || keyEvent->key() == Qt::Key_Backtab) {
177 QApplication::postEvent(
178 m_parent,
new QKeyEvent(keyEvent->type(), keyEvent->key(), keyEvent->modifiers()));
185 else if (event->type() == QEvent::FocusOut) {
186 auto* focusEvent =
dynamic_cast<QFocusEvent*
>(event);
187 QApplication::postEvent(
this,
new QFocusEvent(focusEvent->type(), focusEvent->reason()));
193 return QObject::eventFilter(obj, event);
Defines classes releted to event filtering.
bool eventFilter(QObject *dist, QEvent *event) override
bool eventFilter(QObject *obj, QEvent *event) override
LostFocusFilter(QObject *parent=nullptr)
ShortcodeFilter(QString shortcode, QObject *parent=nullptr)
bool eventFilter(QObject *obj, QEvent *event) override
SpaceKeyEater(QObject *parent=nullptr)
bool eventFilter(QObject *obj, QEvent *event) override
TabFromFocusProxy(QWidget *parent=nullptr)
Passing focus-related events from child widget (e.g. QSpinBox) to parent (e.g. IntEditor) to trigger ...
bool eventFilter(QObject *obj, QEvent *event) override
static void install(QObject *obj)
bool eventFilter(QObject *obj, QEvent *event) override
WheelEventEater(QObject *parent=nullptr)