Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uneditable QListView

I have a QListView displaying a list of items but I don't want the items to be edited (Currently a double click on the item allows you to edit them).

This is my Code:

self.listView = QListView()
self.model = QStringListModel([ "item1" , "item2" , "item3" ])
self.listView.setModel( self.model )

self.layout = QGridLayout()  
self.layout.addWidget(self.listView, 0 , 0 )
self.setLayout(self.layout)
like image 469
Jay Avatar asked Jun 03 '11 10:06

Jay


2 Answers

Adding the line:

self.listView.setEditTriggers(QAbstractItemView.NoEditTriggers)

should fix things for you.

QListView inherits QAbstractItemView which has the method setEditTriggers(). Other possible values for setEditTriggers are available in the docs.

like image 126
Gary Hughes Avatar answered Nov 20 '22 18:11

Gary Hughes


Thanks for the responses. I ended up going with a QListWidget instead as it is not editable by default.

Though I also found if you give the QListView a mouse Double clicked event and set it to do something other than edit the QListView, it overrides the edit function so that works too.

like image 24
Jay Avatar answered Nov 20 '22 18:11

Jay