View Full Version : TreeView ->"read only" [TreeModelCompleter Tutorial]

20th May 2014, 06:16
Hi all,
I played a little bit around with the tutorials and I wondered how to set the TreeView from the TreeModelCompleter as read only...

Some kind of:

~Qt::ItemIsEditable ...

If I try to overwrite the


I get an error, because I can't have a multiple Inheritance with QObject.

I hope you can help me to understand that!
best Regards

20th May 2014, 06:47
How does your code look like when you get that error?


20th May 2014, 08:23
first of all thank you very much for your fast response!
My idea was to insert a code like this:

Qt::ItemFlags MyStandardItemModel::flags(const QModelIndex& index) const
return (QStandardItemModel::flags(index) & ~Qt::ItemIsEditable);

If I do this I get an error as the following: C2352: 'QStandardItemModel::flags' illegal call of non-static member function.
I don't know how to add QAbstractItemModel to my class, because I've already added another subclass of QObject.
Do you have an hint for me?

Is there any other opportunity to make the TreeModelCompleter Example not editable?
best regards

20th May 2014, 08:37
What class does MyStandardItemModel inherit from?

If you want the view to disallow editing on the model (regardless of the model's editability) then you can

view->setEditTriggers(QAbstractItemView::NoEditTriggers) ;

If you want the model to be read only everywhere then you use QAbstractItemModel::flags() to indicate that.

20th May 2014, 10:16
My Code is very similar to the TreeModelCompleter. The only change I made is, that I swapped the modelFromFile() -function from the mainwindow class to the treemodelcompleter class. Right now, I want to set this standard treeview as "read only"
To answer your question, this class inherits from QCompleter.


Added after 1 18 minutes:

Thank you very much for your help! I think the first option works fine for me but nevertheless I would be very interested in how to implement the second option.
best regards

20th May 2014, 21:52
ModelFromFile() builds a QAbstractItmModel subclass not a QCompleter subclass. It is that model that needs to return flags() that do not allow editing. In the example you could simply call setEditable() on each QStandardItem as it was added to the model.