• 5883阅读
  • 1回复

[提问]如何通过QTextBlock设置block的TextFormat? [复制链接]

上一主题 下一主题
离线wang9658
 
只看楼主 正序阅读 楼主  发表于: 2012-05-22
关键词: 求助
textDoc是一个QTextEdit的document()返回的文档对象。
下面的代码原本是要设置某行文本颜色,但是根本不生效。请教一下怎么回事?

  1. QTextBlock blk = textDoc->begin();
  2. int index = 0;
  3. while(blk.isValid()){
  4. qDebug() << "BLOCK:" << blk.text();
  5. index++;
  6. if(1){//index == 10){
  7. QTextCursor cursor(blk);
  8. static QTextCharFormat format;
  9. format.setForeground(Qt::darkYellow);
  10. format.setBackground(Qt::gray);
  11. cursor.setBlockCharFormat(format);
  12. }
  13. blk = blk.next();
  14. }


离线liyjw
只看该作者 1楼 发表于: 2013-03-20
QTextBlockFormat   format;
format.setBackground(Qt::red);
myCursor->setBlockFormat(format);

myCursor->insertText("hello");
快速回复
限100 字节
 
上一个 下一个