Еext in QLineEdit selected on edit start.
--HG-- branch : feature
This commit is contained in:
parent
d81be4f778
commit
0c13d610eb
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user