稍后我想在应用程序中访问QTextList格式,但是似乎总是在创建后将其删除
我已经了解format()
函数
我以这种方式创建QTextList:
cursor = self.textEdit.textCursor()
cursor.insertList(QTextListFormat.ListDisc)
稍后在应用程序中,我想获取格式,即ListDisc或任何其他格式;而我做到了:
list = self.textEdit.textCursor().currentList()
if(list):
print(list.format())
我在调用print的行上收到此错误:
RuntimeError: Internal C++ object (PySide2.QtGui.QTextList) already deleted.
编辑:下面的MCVE在PySide2 5.12.1 Windows 7上运行时给我错误
import sys
from PySide2.QtWidgets import QApplication, QTextEdit, QMainWindow
from PySide2.QtGui import QTextListFormat
class Test(QMainWindow):
def __init__(self, fileName=None):
super(Test, self).__init__()
self.testList()
def testList(self):
self.textEdit = QTextEdit(self)
cursor = self.textEdit.textCursor()
cursor.createList(QTextListFormat.ListDisc)
list = self.textEdit.textCursor().currentList()
if(list):
print(list.format())
if __name__ == '__main__':
app = QApplication(sys.argv)
test = Test()
test.show()