I have a QTextEdit, when I set the text style, for example QTextListFormat::ListCircle, I found the blank space before the line is kept, How to remove these blank space?
this is my text:
- aa
- [][][][]bb
- [][]cc
I want this:
- aa
- bb
- cc
Here is my code:
void RichText::changeStyle(QTextListFormat::Style style)
{
QTextCursor cursor = ui->textEdit->textCursor();
cursor.beginEditBlock();
QTextBlockFormat blockFmt = cursor.blockFormat();
cursor.setBlockFormat(blockFmt);
QTextListFormat listFmt;
if (cursor.currentList()) {
listFmt = cursor.currentList()->format();
} else {
listFmt.setIndent(blockFmt.indent() + 1);
blockFmt.setIndent(0);
cursor.setBlockFormat(blockFmt);
}
auto curStyle = listFmt.style();
if(curStyle == style)
listFmt.setStyle(QTextListFormat::ListStyleUndefined);
else
listFmt.setStyle(style);
cursor.createList(listFmt);
cursor.endEditBlock();
}
I figure it out using the following code: