Issue
Consider the snippet below that creates two item models and views for a single item:
item = QStandardItem("my item")
item_model_1 = QStandardItemModel()
item_model_1.appendRow(item)
item_model_2 = QStandardItemModel()
item_model_2.appendRow(item)
view_1 = QTreeView()
view_1.setModel(item_model_1)
view_2 = QTreeView()
view_2.setModel(item_model_2)
I would like the user to be able to view the item from either view, but have it editable from only one view. Is this possible?
Solution
Use the same model for both views
item = QStandardItem("my item")
item_model = QStandardItemModel()
item_model.appendRow(item)
view_1 = QTreeView()
view_1.setModel(item_model)
view_2 = QTreeView()
view_2.setModel(item_model)
and disable the edit trigger for one of the view
view_2.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
You should also read
https://doc.qt.io/qt-6/model-view-programming.html#using-views-with-an-existing-model
Answered By - Marco F.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.