
* replace aolineedit and aotextedit with event filters * use a button to make evidence editable instead of double click
37 lines
918 B
C++
37 lines
918 B
C++
#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
|