I am using qtableview-s to show some data from sqlite tables. I have 2 tableviews which are essentialy same. They are both showing bus stops (same model) in rows. In first table i am selecting departure and what i would like to achieve is that in second table all entries before the selected one are made non selectable so that user cannot move backward to select them. I was able to hide them using setRowHidden(row,true) but i would like still to see them but not be able to select them.
I tried using flags Qt::ItemFlags (using flags method in custom model) for the row but no matter what i use the rows are still selectable. Does anyone know how to disable row in QTableView so that is still shown but not selectable.
Thanks for the tips/help but in the mean time i found solution (well bug in my code). It was bug in my custom model. I was returning wrong flags for item. For others that might try to do something similar. You have to implement flags method in custom model (QSQLQueryModel derived) and return flag Qt::NoItemFlags for items that you dont want selected. I was returning QAbstractItemModel::flags(index) but there are some default flags allready set.
Qt::ItemFlags busStopsTableModel::flags(const QModelIndex &index) const
{
if(index.row()>lastDisableRowID){
return QAbstractItemModel::flags(index)|Qt::ItemIsSelectable;
}
else
{
return Qt::NoItemFlags;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With