Еext in QLineEdit selected on edit start.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-08-12 11:57:46 +03:00
parent d81be4f778
commit 0c13d610eb
3 changed files with 30 additions and 4 deletions

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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