aboutsummaryrefslogtreecommitdiff
path: root/include/eventfilters.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/eventfilters.h')
-rw-r--r--include/eventfilters.h36
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