Important: Please read the Qt Code of Conduct -

Datachanged signal does not work

  • Hello!
    I have problem with dataChanged signal.

    In my class, inherited from QAbstractItemModel, I have following functions:

    @def columnCount(self, parent):
    return 1

    def data(self, index, role):
    if index.isValid():
    node = self.nodeForIndex(index)
    if role == QtCore.Qt.DisplayRole:
    return node.nodeData[index.column()]
    if role == QtCore.Qt.DecorationRole:
    return node.icon
    if role == QtCore.Qt.EditRole:
    if role == QtCore.Qt.ToolTipRole:

    def flags(self, index):
    return QtCore.Qt.ItemIsEnabled |
    QtCore.Qt.ItemIsSelectable |
    QtCore.Qt.ItemIsDragEnabled |
    QtCore.Qt.ItemIsDropEnabled |

    def headerData(self, section, orientation, role):
    if orientation == QtCore.Qt.Horizontal and
    role == QtCore.Qt.DisplayRole:
    return None

    def index(self, row, column, parent):
    if not parent.isValid():
    parentNode = self.rootNode
    parentNode = parent.internalPointer()

    #childNode = parentNode.childAt(row)
    if parentNode.childAt(row):
        return self.createIndex(row, column, parentNode.childAt(row))
        return QtCore.QModelIndex()

    def nodeForIndex(self, index):
    if index.isValid():
    node = index.internalPointer()
    return node
    return self.rootNode

    def parent(self, index):
    if not index.isValid():
    return QtCore.QModelIndex()

    childNode = index.internalPointer()
    parentNode = childNode.parent
    if not childNode or not parentNode:
        return QtCore.QModelIndex()
    if parentNode == self.rootNode:
        return QtCore.QModelIndex()
    return self.createIndex(parentNode.getRow(), 0, parentNode)

    def setData(self, index, value, role):
    node = self.nodeForIndex(index)
    if role == QtCore.Qt.EditRole:
    self.dataChanged.emit(index, index)
    return True@

    In func setData signal dataChanged.emit() just don't work. I tried to catch it myself, signal emited right and indexe is valid. But my views are not updated. What's wrong?

Log in to reply