高亮光标所在行

syhhl007 2009-11-12 04:28:42
我用如下一句来高亮光标所在行一整行,为什么不行啊?应该如何修改?
ui->textEdit->textCursor().blockFormat().setBackground(Qt::red);
...全文
220 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
syhhl007 2009-11-16
  • 打赏
  • 举报
回复
请问楼上为什么参数QVariant要用bool类型
dext 2009-11-14
  • 打赏
  • 举报
回复
http://doc.trolltech.com/4.5/qtextformat.html
中的 Selection properties
原型是:
void setProperty ( int propertyId, const QVariant & value )
syhhl007 2009-11-13
  • 打赏
  • 举报
回复
sel.format.setProperty(QTextFormat::FullWidthSelection, true);

dext:你的代码的确有效,但如下函数有个地方没看明白。参数true有什么用啊?它的原型是下面的函数吗?
void QTextFormat::setProperty ( int propertyId, const QVector<QTextLength> & value )

Sets the value of the property given by propertyId to value.

winux 2009-11-12
  • 打赏
  • 举报
回复
void MyTextEdit::paintEvent(QPaintEvent *event)
{
QPainter painter(viewport());
QRect r(0,
cursorRect().y(),
viewport()->width(),
QFontMetrics(document()->defaultFont()).lineSpacing()
);
painter.fillRect(r, QColor(59, 231, 186, 0x30));
painter.end();

QTextEdit::paintEvent(event);
}

dext 2009-11-12
  • 打赏
  • 举报
回复
void MainWindow::on_textEdit_cursorPositionChanged() {
QList<QTextEdit::ExtraSelection> extraSelections;
QTextEdit::ExtraSelection sel;
sel.format.setBackground(Qt::red);
sel.format.setProperty(QTextFormat::FullWidthSelection, true);
sel.cursor = ui->textEdit->textCursor();
sel.cursor.clearSelection();
extraSelections.append(sel);
ui->textEdit->setExtraSelections(extraSelections);
}

16,175

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧