textDoc = QTextEdit->document;
...
I want to set one line's color, but no effect. I think for the TextBlock of plaintext, block and line are same things.
int index = 0;
while(blk.isValid()){
qDebug() << "BLOCK:" << blk.text();
index++;
if(1){//index == 10){
format.setForeground(Qt::darkYellow);
format.setBackground(Qt::gray);
cursor.setBlockCharFormat(format);
}
blk = blk.next();
}
QTextBlock blk = textDoc->begin();
int index = 0;
while(blk.isValid()){
qDebug() << "BLOCK:" << blk.text();
index++;
if(1){//index == 10){
QTextCursor cursor(blk);
QTextCharFormat format;
format.setForeground(Qt::darkYellow);
format.setBackground(Qt::gray);
cursor.setBlockCharFormat(format);
}
blk = blk.next();
}
To copy to clipboard, switch view to plain text mode
Bookmarks