【发布时间】:2012-12-17 00:25:57
【问题描述】:
我目前正在开发一个用 Qt 编写的代码编辑器,
我已经设法实现了我想要的大部分功能,即自动完成和语法突出显示,但有一个我无法解决的问题。
我创建了一个模型供QCompleter 使用,它适用于诸如 html 标记和 c++ 关键字(例如 if else 等)之类的内容。
但我想在用户输入时将变量添加到完成者。
所以我在QTextEdit 上创建了一个事件,它会得到消息(我知道我需要检查以确保它是一个变量等,但我只想让它现在工作)。
void TextEdit::checkWord()
{
//going to get the previous word and try to do something with it
QTextCursor tc = textCursor();
tc.movePosition(QTextCursor::PreviousWord);
tc.select(QTextCursor::WordUnderCursor);
QString word = tc.selectedText();
//check to see it is in the model
}
但现在我想弄清楚如何检查该单词是否已经在 QCompleters 模型中,如果不是,我该如何添加它?
我尝试了以下方法:
QAbstractItemModel *m = completer->model();
//dont know what to do with it now :(
【问题讨论】:
标签: qt qt4 qtextedit qcompleter