aboutsummaryrefslogtreecommitdiff
path: root/src/eventfilters.cpp
blob: 6f0b0f1208294fb5fdb6910d4cde58b31e056767 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "eventfilters.h"

bool AOLineEditFilter::eventFilter(QObject *obj, QEvent *event)
{
  QLineEdit *lineEdit = qobject_cast<QLineEdit *>(obj);
  if (event->type() == QEvent::FocusOut && lineEdit != nullptr && preserve_selection)
  { // lost focus
    int start = lineEdit->selectionStart();
    int len = lineEdit->selectionLength();

    if (start != -1 && len != -1)
    {
      lineEdit->setSelection(start, len);
      return true;
    }
  }
  return false;
}