I am opening a QDialog which contains a QLineEdit. I want the QLineEdit to have keyboard focus initially, with the blinking cursor as a visual cue. Simple, right?
Calling line_edit->setFocus()
has no effect.
Calling line_edit->grabKeyboard()
gives it input focus BUT
- the blinking caret doesn't move to
line_edit
- if I click into a different QLineEdit, the blinking caret goes there but keypresses are still delivered to
line_edit
If I do neither, I have to click into line_edit
to get the caret and input focus. Looking at the source code for QLineEdit::mousePressEvent
it seems that the critical function is QWidgetLineControl::moveCursor
, but that's not accessible via the public API and peeking further into the source doesn't show anything promising.
So how do I move the damn keyboard input cursor?