#include "eventfilters.h" bool AOLineEditFilter::eventFilter(QObject *obj, QEvent *event) { QLineEdit *lineEdit = qobject_cast(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; }