Quantcast
Channel: User spraff - Stack Overflow
Viewing all articles
Browse latest Browse all 66

How can I move the keyboard cursor/focus to a QLineEdit?

$
0
0

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?


Viewing all articles
Browse latest Browse all 66

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>