我需要从 QTextDocument 中删除一些段落。我已经尝试过此主题的代码:Remove a line/block from QTextEdit,但 QTextDocument.drawContents 输出空行代替已删除的块。
# create sample document
doc = QTextDocument()
cursor = QTextCursor(doc)
cursor.movePosition(QTextCursor.End)
cursor.insertText("First line\nSecond line\nThird line")
# now remove first line
cursor = QTextCursor(doc.findBlockByLineNumber(0))
cursor.select(QTextCursor.BlockUnderCursor)
cursor.removeSelectedText()
那么,如何彻底清除阻塞呢?