Reputation: 3341
I need to be able to programmatically select some rows of a TableView, hence showing the selected rows to the user. Of course the user should not be able to change the selected rows by clicking here and there.
Currently, the only way I found to disable the user's interaction is with:
self.table_view.setEnabled(False)
Altough this resolves the user's selection problem, it also changes the aspect of the table, making it all greyed out:
How can I restore the original style, with the selected rows displaying as blue?
Upvotes: 1
Views: 2703
Reputation: 103
If I correctly understand your question, you have to play with properties :
setSelectionBehavior()
table_view.setSelectionMode(QtWidgets.QAbstractItemView.NoSelection)
table_view.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
Upvotes: 1
Reputation: 344
Open up QDesigner and load your .ui file. Click on your QTableView and in the Property Editor (right side panel) scroll down to the purple area. There you will see editTriggers
, expand that. Check the first one that says NoEditTriggers
.
This will disable the user from editing cells in the table. Let me know if my instructions weren't clear enough and I can provide pics.
Upvotes: 2