qt中 plaintextedit高亮问题

void MainWindow::hilightCurrentLine()
{
    hilightCurrentLinestart();
    QList<QTextEdit::ExtraSelection> extraSelections;//提供一种方式显示选择的文本

    QTextEdit::ExtraSelection selection;
    QColor lineColor = QColor(Qt::yellow).lighter(160);
    selection.format.setBackground(lineColor);
    selection.format.setProperty(QTextFormat::FullWidthSelection, true);

    QTextCursor currentCursor(ui->plainTextEdit->textCursor());//返回当前可见光标副本
 //   currentCursor.movePosition(12,0,5);
    currentCursor.movePosition(QTextCursor::Down,QTextCursor::MoveAnchor,anycnc.LINE);//移动副本光标

    ui->plainTextEdit->setTextCursor(currentCursor);//更新可见光标
    selection.cursor=ui->plainTextEdit->textCursor();//新光标位置
    selection.cursor.clearSelection();//通过设置锚到光标位置清除当前的选择
    extraSelections.append(selection);

    /*This function allows temporarily marking certain regions in the document with a given color,
    specified as selections.
    This can be useful for example in a programming editor to mark a whole line of text
    with a given background color to indicate the existence of a breakpoint.
    */

    ui->plainTextEdit->setExtraSelections(extraSelections);//设置高亮
}

 
 
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值