【问题标题】:highlight a word that has x and y as a position inside a qtextedit突出显示在 qtextedit 中具有 x 和 y 作为位置的单词
【发布时间】:2013-08-21 14:24:50
【问题描述】:

我正在使用 Qt 编写代码编辑器。我有一个问题,我想知道如何使用它的 x 和 y 位置(行和列)在我的 textedit 中突出显示一个单词,请问有什么想法吗?

使用这种方法我可以获得位置并突出显示一些字符,但之后如果我想显示其他文本,则所有文本都被突出显示。

void MainWindow::Target(int row, int colum) { QTextEdit* TempTextEdit = ui->textEdit; QTextDocument* document = TempTextEdit->document(); QTextCursor 光标(文档); //cursor.beginEditBlock(); // cursor.setPosition(0); cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, row-1); cursor.setPosition(colum); cursor.setPosition(colum+2, QTextCursor::KeepAnchor); QTextCharFormat plainFormat(cursor.charFormat()); QTextCharFormat colorFormat = plainFormat; colorFormat.setForeground(Qt::red); colorFormat.setFontUnderline(true); cursor.movePosition(QTextCursor::WordRight, QTextCursor::KeepAnchor); cursor.mergeCharFormat(colorFormat); // cursor.endEditBlock(); TempTextEdit->setTextCursor(光标); }

【问题讨论】:

    标签: c++ qt


    【解决方案1】:

    您可以使用QSyntaxHighlighter

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-07
      • 2015-10-17
      • 2012-11-01
      • 1970-01-01
      相关资源
      最近更新 更多