Issue
Using QStandardItemModel in a QTreeView, itemChanged signals are not triggered (for example on rename). If I recall correctly this was functioning in a much earlier PyQt5 version.
class Main(QMainWindow):
def __init__(self):
super().__init__()
self.resize(200, 100)
self.dataTree = QTreeView(self)
self.dataTree.setSelectionMode(QAbstractItemView.SingleSelection)
self.dataTree.resize(200, 100)
self.dataModel = QStandardItemModel(self.dataTree)
self.dataModel.setHorizontalHeaderLabels(['Sources'])
self.dataModelParent = self.dataModel.invisibleRootItem()
self.dataTree.setModel(self.dataModel)
self.dataModel.itemChanged.connect(lambda: self.itemChanged)
master = QStandardItem('test1')
self.dataModel.appendRow(master)
@pyqtSlot(QStandardItem)
def itemChanged(self, item):
print('Item Changed')
if __name__ == '__main__':
app = QApplication(sys.argv)
mainWindow = QMainWindow()
Main = Main()
Main.show()
app.exec_()
Solution
Consider the line...
self.dataModel.itemChanged.connect(lambda: self.itemChanged)
Here, your lambda doesn't actually do anything. Instead you need something like...
self.dataModel.itemChanged.connect(lambda item: self.itemChanged(item))
Answered By - G.M.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.