TreeView ->"read only" [TreeModelCompleter Tutorial]
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:
Code:
~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
Re: TreeView ->"read only" [TreeModelCompleter Tutorial]
How does your code look like when you get that error?
Cheers,
_
Re: TreeView ->"read only" [TreeModelCompleter Tutorial]
Hi,
first of all thank you very much for your fast response!
My idea was to insert a code like this:
Code:
Qt::ItemFlags MyStandardItemModel::flags(const QModelIndex& index) const
{
}
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
Re: TreeView ->"read only" [TreeModelCompleter Tutorial]
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
If you want the model to be read only everywhere then you use QAbstractItemModel::flags() to indicate that.
Re: TreeView ->"read only" [TreeModelCompleter Tutorial]
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.
Thanks
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
C
Re: TreeView ->"read only" [TreeModelCompleter Tutorial]
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.