4

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?

4

3 回答 3

3

当用户单击按钮时,您应该使用以下命令将焦点返回给文本编辑setFocus()

myTextEdit->setFocus();
于 2013-05-14T14:37:19.313 回答
1

在按钮按下处理程序中,调用 QTextEdit 的setFocus()命令。

于 2013-05-14T14:37:31.883 回答
1

有个更好的方法。选择您的按钮并将 focuspolicy 更改为 NoFocus。

然后您可以单击您的按钮,它不会将焦点从您的 TextEdit 窗口中拉出,您可以运行您的按钮执行的代码,它会将光标留在编辑窗口中。

于 2017-05-09T18:24:35.417 回答