0

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();
}
demonplus
  • 5,613
  • 12
  • 49
  • 68
seme
  • 43
  • 7
  • In which class is the code above? Make sure the class containing that code has key focus, otherwise it won't get the QKeyEvent. Do you get the print out of the QDebug() call? – Aaron Nov 30 '15 at 09:45

1 Answers1

0

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

demonplus
  • 5,613
  • 12
  • 49
  • 68