Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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:
    return node.name
    if role == QtCore.Qt.ToolTipRole:
    return node.name

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

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

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

    #childNode = parentNode.childAt(row)
    if parentNode.childAt(row):
        return self.createIndex(row, column, parentNode.childAt(row))
    else:
        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:
    node.changeName(value)
    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