PDA

View Full Version : Setting Editing Possibilities in Model/View set up



Airswoop1
29th May 2009, 21:01
I am currently just fooling around with the Model/View architecture in preparation for working with a larger application that deals more extensively with this design. I am working on the TrackEditor example, that can be found at: http://http://www.informit.com/title/0132354160 (chapter 10) . I have extended this example to truly have a Model View architecture with a trackmodel class added, as well as a Tracks class that basically acts as a separate data source. The problem I am running into is that I cannot seem to figure out how to isolate a column in the model and remove the possibility of editing the data. I know that I need to modify the model in some way but my trackmodel class is subclassed from the QAbstractTableModel which unfortunately has limited capabilities with isolating single columns of data (as far as I can tell). I am attempting to do this using flags and the itemIsEditable but I cannot seem to find the correct syntax. I am somewhat new to Qt so any help or direction would be helpful. THANKSSS.:confused:

wysota
30th May 2009, 02:01
How about:


Qt::ItemFlags MyModel::flags(const QModelIndex &index) const {
Qt::ItemFlags fl = QAbstractTableModel::flags(index);
if(index.column()==4) fl &= ~Qt::ItemIsEditable; // clear the editable flag for column no. "4"
return fl;
}