解決Qt設置QTextEdit行高的問題
更新時間:2022年04月09日 09:32:43 作者:師從名劍山
這篇文章介紹了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設置了文字之后,才會生效,放在構造函數(shù)里不會生效
像這樣是不行的
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中所有的段落,對一個一個的段落進行設置。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
C++ Thread實現(xiàn)簡單的socket多線程通信
本文主要介紹了C++ Thread實現(xiàn)簡單的socket多線程通信,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-07-07

