How to use the QstandardItemModel

Asked 2 years ago, Updated 2 years ago, 16 views

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

2022-09-30 15:48

1 Answers

QStandardItem.setData second argument with a value of QtCore.Qt.UserRole "above" and you can get the same value for the QStandardItem.data argument.


2022-09-30 15:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.