Это более старый вопрос, но, тем не менее, я попал сюда в поисках решения именно этой проблемы.Это может быть решено следующим образом:
Создайте класс, полученный из QLineEdit
и переопределите focusInEvent
в заголовке:
virtual void focusInEvent(QFocusEvent *event) override;
Затем реализуйте его так:
void MyLineEdit::focusInEvent(QFocusEvent *event)
{
// First let the base class process the event
QLineEdit::focusInEvent(event);
// Then select the text by a single shot timer, so that everything will
// be processed before (calling selectAll() directly won't work)
QTimer::singleShot(0, this, &QLineEdit::selectAll);
}
На всякий случай, если кто-то еще задается вопросом, как это можно сделать; -)