日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

解決Qt設置QTextEdit行高的問題_C 語言

作者:師從名劍山 ? 更新時間: 2022-06-10 編程語言

解決方法:

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中所有的段落,對一個一個的段落進行設置。

原文鏈接:https://blog.csdn.net/qq_44723937/article/details/122673979

欄目分類
最近更新