I am currently using PyQt5 to create a GUI for data processing, but I would like to display the data name that I want to edit on QListView and select it on the list to perform each process.So I was able to use the QstandardItemModel to display it.
item=QtGui.QStandardItem(filename)
item.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsDragEnabled | QtCore.Qt.ItemIsEditable)
item.setData(QtCore.QVariant(QtCore.Qt.Checked), QtCore.Qt.CheckStateRole)
Added to self.ui.Imodel.appendRow(item)#List
However, I want the item on the list to be name editable (Qt.ItemIsEditable) and movable (Qt.ItemIsDragEnabled), so I want to store file path and other information in ItemModel so that I can always get it even if I edit or move the name.
If anyone knows, please let me know.
python
QStandardItem.setData
second argument with a value of QtCore.Qt.UserRole
"above" and you can get the same value for the QStandardItem.data
argument.
© 2024 OneMinuteCode. All rights reserved.