这篇文章介绍了Qt设置QTextEdit行高的方法,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
解决方法:
QTextDocument* doc = ui->edtCountryIntroduce->document();
for(QTextBlock it = doc->begin(); it != doc->end(); it = it.next())
{
QTextCursor textCursor(it);
QTextBlockFormat textBlockFormat = it.blockFormat();
//set line height
textBlockFormat.setLineHeight(24,QTextBlockFormat::FixedHeight);
textCursor.setBlockFormat(textBlockFormat);
ui->edtCountryIntroduce->setTextCursor(textCursor);
}
需要在QTextEdit设置了文字之后,才会生效,放在构造函数里不会生效
像这样是不行的
QTextCursor textCursor = ui->textEdit->textCursor();
QTextBlockFormat textBlockFormat;
//set line height
textBlockFormat.setLineHeight(24,QTextBlockFormat::FixedHeight);
textCursor.setBlockFormat(textBlockFormat);
ui->textEdit->setTextCursor(textCursor);
因为这里虽然是给整个textEdit设置,但是实际上,只是给第一段设置了。所以如果如果要对所有的段落进行设置就需要遍历当前textEdit的document中所有的段落,对一个一个的段落进行设置。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程学习网。
沃梦达教程
本文标题为:解决Qt设置QTextEdit行高的问题


基础教程推荐
猜你喜欢
- C利用语言实现数据结构之队列 2022-11-22
- C语言基础全局变量与局部变量教程详解 2022-12-31
- C++详细实现完整图书管理功能 2023-04-04
- C/C++编程中const的使用详解 2023-03-26
- 如何C++使用模板特化功能 2023-03-05
- C++使用easyX库实现三星环绕效果流程详解 2023-06-26
- 详解c# Emit技术 2023-03-25
- C语言 structural body结构体详解用法 2022-12-06
- C++中的atoi 函数简介 2023-01-05
- 一文带你了解C++中的字符替换方法 2023-07-20