Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt How to make QStringList non editable

Tags:

list

listview

qt

My structure is like that,

QStringList list;
list << "Hello" << "world" << "Blah" << "Blah ;
QStringListModel *model = new QStringListModel;
model->setStringList(list);
QListView *view = new QListView(this);
view->setModel(model);

Now I want to make the list non editable on my GUI.

like image 284
Dewsworld Avatar asked Mar 26 '12 13:03

Dewsworld


2 Answers

Add

view->setEditTriggers(QAbstractItemView::NoEditTriggers);
like image 100
Jokahero Avatar answered Oct 16 '22 11:10

Jokahero


Derive your model from QStringListModel and override flags() to clear ItemIsEditable flag.

like image 33
Stephen Chu Avatar answered Oct 16 '22 11:10

Stephen Chu