diff options
| author | oldmud0 <oldmud0@users.noreply.github.com> | 2021-12-18 22:34:04 -0600 |
|---|---|---|
| committer | oldmud0 <oldmud0@users.noreply.github.com> | 2021-12-18 22:34:04 -0600 |
| commit | b0e9f8dbe57df5e688d9583987d7e378eebd72b4 (patch) | |
| tree | 18824b6a05fddfa71e4c1240023fc916d8ef4790 /include/eventfilters.h | |
| parent | cf12168ebd426d7658d7f7021c47be519caa215a (diff) | |
| parent | 641cca65044e41e49e5a871f0d60138b61c1bab3 (diff) | |
Merge branch 'master' into feature/http-ms
Diffstat (limited to 'include/eventfilters.h')
| -rw-r--r-- | include/eventfilters.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/include/eventfilters.h b/include/eventfilters.h new file mode 100644 index 00000000..7847608d --- /dev/null +++ b/include/eventfilters.h @@ -0,0 +1,36 @@ +#ifndef EVENTFILTERS_H +#define EVENTFILTERS_H + +#include <QEvent> +#include <QLineEdit> + +class AOLineEditFilter : public QObject +{ + Q_OBJECT +public: + bool preserve_selection = false; + +protected: + bool eventFilter(QObject *obj, QEvent *event) override { + QLineEdit *lineEdit = qobject_cast<QLineEdit *>(obj); + if (event->type() == QEvent::FocusOut && lineEdit != nullptr && preserve_selection) { // lost focus + int start = lineEdit->selectionStart(); + #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + int len = lineEdit->selectionLength(); + #else + int len = lineEdit->selectedText().length(); + #endif + if (start != -1 && len != -1) { + lineEdit->setSelection(start, len);\ + return true; + } + } + return false; + } +signals: + void double_clicked(); +}; + + + +#endif // EVENTFILTERS_H |
