python - 如何在 PySide2 中获取 QTextList 的格式
问题描述
我想稍后在我的应用程序中访问一个 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()
解决方案
推荐阅读
- amazon-web-services - 断开连接:没有可用的受支持的身份验证方法(服务器发送:publickey)
- python - Turtle Graphics 完成后停止响应
- jquery - 无法从远程 ajax 请求中获取图像
- java - 我在查询中遇到错误
- ruby-on-rails - 验证失败时Rails嵌套对象消失
- javascript - 未找到 Jquery AJAX 404 form.php
- c++ - OpenGL 2d三角形围绕中心旋转
- html - 电子按钮有奇怪的造型
- node.js - 请在 docker npm test 中设置“CHROME_BIN”环境变量
- java - 获取外部程序中的所有@test (TestNg) 方法