import sys from PySide2.QtWidgets import QWidget, QPlainTextEdit, QApplication, QVBoxLayout from PySide2.QtCore import QMimeData class TextEditRemoveMime1(QPlainTextEdit): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def createMimeDataFromSelection(self): mime = super().createMimeDataFromSelection() mime.clear() mime.setData("text/plain", b"") mime.setText(self.textCursor().selectedText()) mime.setHtml("") return mime class TextEditRemoveMime2(QPlainTextEdit): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def createMimeDataFromSelection(self): mime = QMimeData() text = self.textCursor().selectedText() mime.setText(text) return mime class Example(QWidget): def __init__(self): super().__init__() vbox = QVBoxLayout() # Has styleing information plainTextEdit = QPlainTextEdit(self) vbox.addWidget(plainTextEdit) # Still has styleing information, does not crash plainTextEdit = TextEditRemoveMime1(self) vbox.addWidget(plainTextEdit) # Crashes in PySide2 but does work as expected in PyQt5 plainTextEdit = TextEditRemoveMime2(self) vbox.addWidget(plainTextEdit) self.setLayout(vbox) self.show() if __name__ == "__main__": app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_())