seme
seme

Reputation: 53

QLineEdit the function selectAll() didn't work?

I user QLineEdit like this, and anybody know anything is wrong:

if (event->modifiers() == Qt::ControlModifier 
  && event->key()== Qt::Key_A) {
    qDebug() << "Ctrl+A pressed";
    m_lineEdit->setFocus(Qt::ShortcutFocusReason);
    m_lineEdit->selectAll();
}

Upvotes: 0

Views: 386

Answers (1)

demonplus
demonplus

Reputation: 5801

Try to use timer to make sure all events are processed and then selection is done:

QTimer::singleShot(0, m_lineEdit, SLOT(selectAll()));

instead of m_lineEdit->selectAll();

Upvotes: 0

Related Questions