0
QTextCursor c = ui->textEdit->textCursor();
QChar cc = c.PreviousCharacter;

这不会产生错误,但也不会产生结果(不确定 cc 中存储了什么)。我想在 QTextEdit 中收集以前键入的字符,无论光标在哪里(例如,不收集 QTextEdit 中的最后一个字符,而是最后键入的字符)。有人吗?谢谢!

更新:

终于明白了。见代码。

QTextCursor cursor = ui->textEdit->textCursor();
cursor.select(QTextCursor::WordUnderCursor);
QString c = cursor.selectedText().right(1);
4

1 回答 1

2

QTextCursor::PreviousCharacter is an enumeration, so you will just store the int value of PreviousCharacter in that enumeration. It's supposed to be used like this: c.movePosition(QTextCursor::PreviousCharacter) meaning "move the cursor to the previous character", meaning to the next character to the left if you're typing in a Western left-to-right script, vice versa in RTL (i.e. Arabic) scripts. It doesn't keep track of the letters you type. You probably need to implement a key event handler that logs the keypresses.

于 2012-04-17T10:27:27.160 回答