[Solved] How can i make a Particular Column as Non Editable in QTableView
-
wrote on 22 Oct 2012, 12:41 last edited by
I have a QTableView with 4 Rows and 4 columns each representing their data's in it. By default the QTableView is Editable. Now i want to make any Particular Column as non Editable in my QTableView. How can i make a partticular column as a non editable column..?
Thanks i& Regards...
-
wrote on 22 Oct 2012, 14:01 last edited by
Well, you can't if you ask me. I had the same problem with a double click setup on a cell. The solution I did was check the QIndex in the model and when it's the wrong column, don't do anything with it.
That should do the trick. No idea if there are better ways to do it! -
wrote on 22 Oct 2012, 17:42 last edited by
You can modify the model so that QAbstractItemModel::flags() doesn't return the flag Qt::ItemIsEditable for all the indexes of the non-editable columns, or if you can't modify the model because, for example, you want the columns to be editable in another view, you can instead use a proxy model and redefine its flags() function.
-
wrote on 23 Oct 2012, 06:04 last edited by
Thanks a lot for your replies.. :)
-
wrote on 23 Oct 2012, 07:57 last edited by
http://www.qtcentre.org/threads/9020-QTreeView-rows-editable?p=48078#post48078
Check this, I also see there is a option in QStandardItemModel in method setData in third param to pass the flag as: Qt::DisplayRole, maybe it will prevent editable row, I'm not sure about this.
http://doc.qt.digia.com/qt/qstandarditemmodel.html#setData
Regards.
-
wrote on 23 Oct 2012, 08:48 last edited by
Yeah i solved it. Thanks all for your suggstions. Here's my Coding.. Here, I had sub classed my Standard items.
@Qt::ItemFlags MyStandardItemModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags flags;flags = QAbstractItemModel::flags(index); if (!(index.column() == 1) && !(index.column() == 3)) { if(!(index.row()==1) && !(index.row() == 3)) { flags |= Qt::ItemIsEditable; return flags; } } return QAbstractItemModel::flags(index);
}
@Thanks and Regards....
-
wrote on 23 Oct 2012, 14:01 last edited by
There is also a ready-made "proxy model":http://qt-project.org/wiki/QSortFilterProxyModel_subclass_for_text_alignment_-and_readonly_columns available on the wiki for this.
3/7