The code below breaks on self.emit line. It works fine in PyQt4. How to fix this code so it works in PyQt5?
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QObject, pyqtSignalclass ItemDelegate(QtWidgets.QItemDelegate):def __init__(self, parent):QtWidgets.QItemDelegate.__init__(self, parent)def createEditor(self, parent, option, index):return QtWidgets.QLineEdit()@QtCore.pyqtSlot()def setModelData(self, editor, model, index): self.emit(QtCore.SIGNAL("dataChanged(QModelIndex,QModelIndex)"), index, index)
Edited later:
A working solution:
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QObject, pyqtSignalclass Communicate(QObject):data_changed = pyqtSignal(QtCore.QModelIndex, QtCore.QModelIndex)class ItemDelegate(QtWidgets.QItemDelegate):def __init__(self, parent):QtWidgets.QItemDelegate.__init__(self, parent)self.c = Communicate()@QtCore.pyqtSlot()def setModelData(self, editor, model, index):self.c.data_changed.emit(index, index)