解决方法:
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中所有的段落,对一个一个的段落进行设置。
热门文章
- 成都领养宠物中心电话号码(成都领养宠物中心电话号码是多少)
- 1月26日|SSR/Shadowrocket/Clash/V2ray每天更新23M/S免费节点订阅链接地址分享
- JavaWeb项目基于SpringBoot框架实现统一的数据返回格式 + 统一异常处理 + 统一日志处理
- 动物医院牌匾设计图片(动物医院名片设计)
- 动物医院资质级别有哪些类型的(动物医院资质级别有哪些类型的证书)
- 1月19日|Shadowrocket/Clash/SSR/V2ray每天更新19.8M/S免费节点订阅链接地址分享
- 塞尔达海拉鲁神庙位置(塞尔达海拉鲁图鉴定位神庙)
- 11月12日|Clash/V2ray/SSR/Shadowrocket每天更新21.5M/S免费节点订阅链接,付费节点订阅推荐
- 11月17日|Shadowrocket/Clash/V2ray/SSR每天更新21.1M/S免费节点订阅链接,付费节点订阅推荐
- 基于Apache Hudi和Debezium构建CDC入湖管道