HOWTO: make a QLineEdit select all the text when clicked on?
On both the QEvent::Enter and QEvent::FocusIn of the QLineEdit, I am calling selectAll(), but it isn't working as desired...
Everything gets selected ( because of QEvent::FocusIn, I think), but on the mouse down or something the selectAll is lost.
Any thoughts on how to safely do a selectAll so I can simply type over the existing value?
Re: HOWTO: make a QLineEdit select all the text when clicked on?
Code:
connect(this, SIGNAL(clicked()), this, SLOT(selectAll()));
Re: HOWTO: make a QLineEdit select all the text when clicked on?
Does QLineEdit have a clicked() signal :rolleyes:
Re: HOWTO: make a QLineEdit select all the text when clicked on?
Apparently no :-)
Monday morning I guess. I assumed all widgets had a clicked signal. Why don't they?
Anyway, here's the signal:
Code:
{
...
signals:
void clicked();
...
};
// Edit: or mouseReleaseEvent(...) according to your taste
void MyLineEdit::mousePressEvent(...)
{
emit clicked();
}
I think, but I guess I need to get some more cafeine to wake up.
Re: HOWTO: make a QLineEdit select all the text when clicked on?
Quote:
Originally Posted by
scarleton
but on the mouse down or something the selectAll is lost.
To prevent such behaviour, you'd have to filter out all unwanted events. But then you won't be able to do things as selecting parts of the input from the widget with the mouse and stuff. I think that what you really want is something like this:
Code:
public:
protected:
m_firstChar = true;
}
if(m_firstChar /* && !ke->text().isEmpty() */) { // the commented part is optional
clear();
m_firstChar = false;
}
}
private:
bool m_firstChar;
};