简体   繁体   中英

Qt: How to set topMargin of paragraph in QTextEdit

I am trying to set a margin above the first paragraph of a QTextEdit . The problem is that it only shows up above the second paragraph; between the first and the second paragraph.

My current code is:

auto doc = ui->textEdit->document();
auto blockFormat = doc->begin().blockFormat();
blockFormat.setTopMargin(100);
QTextCursor{doc->begin()}.setBlockFormat(blockFormat);

Is this the intended behavior of QT? How would I achieve the desired outcome of having a margin above every paragraph, including the first?

This seems to be by design. A simple workaround would be to insert an empty paragraph, or a paragraph with a transparent 1x1 image.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM