Reputation: 881
I cannot find a way to activate a cursor inside a QTextEdit without clicking inside the actual widget. What I want to be able to do is, type something in side the QTextEdit window, click on a QPushButton and have the cursor stay active inside the QTextEdit without having to click in the window again.
Ideas?
Upvotes: 4
Views: 3827
Reputation: 4394
In the button press handler, call your QTextEdit's setFocus()
command.
Upvotes: 1
Reputation: 1548
There is a better way. Select your button and change focuspolicy to NoFocus.
Then you can click on your button and it will not pull the focus from your your TextEdit window, and you can run the code that your button does and it will leave the cursor in the edit window.
Upvotes: 1
Reputation: 28091
When the user clicks the button, you should give the focus back to the text edit using setFocus()
:
myTextEdit->setFocus();
Upvotes: 3