Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
None
-
5.14.0
-
None
-
-
ca5496ab7360a257e81dbc9d8bac653154af7dd3 (pyside/pyside-setup/5.14)
Description
I make sure this bug happens with PySide2 , not in PyQt5 and C++ Qt.
With PySide2, if I subclass QTextDocument, and override createObject, kernel stops.
This is the PySide2 Version as the Code of
A specialist recommended I report this bug for the future.
The way of avoiding this bug is to use self.obj instead of obj.
or append the obj into a container.
PySide2 trashes the local variable soon.
from PySide2 import QtWidgets from PySide2 import QtGui from PySide2 import QtCore import PySide2 import sys import os dirname = os.path.dirname(PySide2.__file__) plugin_path = os.path.join(dirname, 'plugins', 'platforms') os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path class TextEdit(QtWidgets.QTextEdit): def __init__(self, parent=None): super(TextEdit, self).__init__(parent=None) document = TextDocument(self) self.setDocument(document) class TextDocument(QtGui.QTextDocument): def __init__(self, parent=None): super(TextDocument, self).__init__(parent=None) self.setParent(parent) def createObject(self, f): obj = QtGui.QTextObject(self) if f.isListFormat(): obj = QtGui.QTextList(self) elif f.isTableFormat(): obj = QtGui.QTextTable(self) elif f.isFrameFormat(): obj = QtGui.QTextFrame(self) return obj def main(): if QtWidgets.QApplication.instance() is not None: app = QtWidgets.QApplication.instance() else: app = QtWidgets.QApplication([]) mainwindow = TextEdit() mainwindow.show() sys.exit(QtWidgets.QApplication.exec_()) if __name__ == "__main__": main()