Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QT4 Qtableview disable selection of rows

Tags:

qt

qt4

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.

like image 584
roko Avatar asked Dec 05 '25 01:12

roko


1 Answers

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;
    }

 }
like image 72
roko Avatar answered Dec 07 '25 17:12

roko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!