【发布时间】:2021-12-17 02:42:54
【问题描述】:
我正在尝试将所选行设置为项目符号并返回,这里我将缩进设置为 0,它会破坏项目符号,但 list 属性仍然为 true,因此此代码不会将同一行设置回项目符号再次列表,如何清除底层列表格式,或者最好的方法是什么?
def bullet_list(self):
cursor = self.textEdit.textCursor()
list = cursor.currentList()
if list:
listfmt = cursor.currentList().format()
listfmt.setIndent(0)
cursor.createList(listfmt)
self.textEdit.setTextCursor(cursor)
self.textEdit.setFocus()
else:
listFormat = QTextListFormat()
style = QTextListFormat.Style.ListDisc
listFormat.setStyle(style)
cursor.createList(listFormat)
self.textEdit.setTextCursor(cursor)
self.textEdit.setFocus()
【问题讨论】: