I am trying to change the default behavior when dropping a file in QtextEdit
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(869, 499)
self.verticalLayout = QtWidgets.QVBoxLayout(Dialog)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.textEdit = QtWidgets.QTextEdit(Dialog)
self.textEdit.setObjectName("textEdit")
self.horizontalLayout_2.addWidget(self.textEdit)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.textEdit.setAcceptDrops(True)
self.textEdit.dropEvent = self.dropEvent
def dropEvent(self, event):
event.setDropAction(QtCore.Qt.CopyAction)
if event.mimeData().hasText():
print(event.mimeData().text())
event.accept()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
But after performing dropEvent, the cursor in TextEdit stops moving.
What am I missing?