Qt 多文本框设置行距和间距在这里插入代码片
QTextDocument *document = ui->textEdit->document(); //获取文档对象 QTextFrame *rootFrame = document->rootFrame(); // 获取根框架 QTextFrameFormat format; // 创建框架格式 QColor color(255,255,255); color.setAlpha(100); format.setBorderBrush(QBrush(color)); // 边界颜色 format.setBorder(10); // 边界宽度 rootFrame->setFrameFormat(format); // 框架使用格式 QTextCursor cursor = ui->textEdit->textCursor(); //为光标指定一个行高为20的段落格式 QTextBlockFormat block_format; block_format.setLineHeight(40, QTextBlockFormat::FixedHeight); // 行距 QFont font; // 字体间隔 font.setLetterSpacing(QFont::AbsoluteSpacing,5); //AbsoluteSpacing PercentageSpacing //block_format.setTextIndent(0); cursor.setBlockFormat(block_format); //把光标再设置给edit ui->textEdit->setTextCursor(cursor); ui->textEdit->setFont(font);