diff --git a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp index ec60822b6..14a29f957 100644 --- a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp +++ b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp @@ -85,7 +85,6 @@ void DialogEditLabel::ShowLineDetails() { ui->lineEditLine->blockSignals(true); ui->lineEditLine->setText(line->text()); - ui->lineEditLine->selectAll(); ui->lineEditLine->setFocus(); ui->lineEditLine->blockSignals(false); diff --git a/src/libs/vwidgets/vlineedit.cpp b/src/libs/vwidgets/vlineedit.cpp index fb1d78162..392fa657a 100644 --- a/src/libs/vwidgets/vlineedit.cpp +++ b/src/libs/vwidgets/vlineedit.cpp @@ -30,19 +30,29 @@ //--------------------------------------------------------------------------------------------------------------------- VLineEdit::VLineEdit(QWidget *parent) - : QLineEdit(parent) + : QLineEdit(parent), + m_selectOnMousePress(false) {} //--------------------------------------------------------------------------------------------------------------------- VLineEdit::VLineEdit(const QString &contents, QWidget *parent) - : QLineEdit(contents, parent) + : QLineEdit(contents, parent), + m_selectOnMousePress(false) {} +//--------------------------------------------------------------------------------------------------------------------- +void VLineEdit::focusInEvent(QFocusEvent *e) +{ + QLineEdit::focusInEvent(e); + selectAll(); + m_selectOnMousePress = true; +} + //--------------------------------------------------------------------------------------------------------------------- void VLineEdit::focusOutEvent(QFocusEvent *e) { const int start = selectionStart(); - int selectionLength = selectedText().length(); + const int selectionLength = selectedText().length(); const bool wasTextSelected = hasSelectedText(); QLineEdit::focusOutEvent(e); @@ -53,3 +63,14 @@ void VLineEdit::focusOutEvent(QFocusEvent *e) } } +//--------------------------------------------------------------------------------------------------------------------- +void VLineEdit::mousePressEvent(QMouseEvent *e) +{ + QLineEdit::mousePressEvent(e); + if(m_selectOnMousePress) + { + selectAll(); + m_selectOnMousePress = false; + } +} + diff --git a/src/libs/vwidgets/vlineedit.h b/src/libs/vwidgets/vlineedit.h index 7dd0df160..9b9561608 100644 --- a/src/libs/vwidgets/vlineedit.h +++ b/src/libs/vwidgets/vlineedit.h @@ -33,12 +33,18 @@ class VLineEdit : public QLineEdit { + Q_OBJECT public: VLineEdit(QWidget * parent = nullptr); VLineEdit(const QString &contents, QWidget *parent = nullptr); protected: + virtual void focusInEvent(QFocusEvent *e) Q_DECL_OVERRIDE; virtual void focusOutEvent(QFocusEvent *e) Q_DECL_OVERRIDE; + virtual void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE; +private: + Q_DISABLE_COPY(VLineEdit) + bool m_selectOnMousePress; }; #endif // VLINEEDIT_H