网上搜了很多,大部分用起来有问题,要么只能修改第一段的行间距,要么就不生效。后来找了很久终于找到一个可以用的,现贴在下面,每次使用调用一次即可
QTextDocument *doc = ui->textEdit_label->document();
QTextCursor textcursor = ui->textEdit_label->textCursor();
for(QTextBlock it = doc->begin(); it !=doc->end();it = it.next())
{
QTextBlockFormat tbf = it.blockFormat();
tbf.setLineHeight(lineSpacing,QTextBlockFormat::LineDistanceHeight);
textcursor.setPosition(it.position());
textcursor.setBlockFormat(tbf);
ui->textEdit_label->setTextCursor(textcursor);
}