How to turn off selection cells by tab and shif+tab in QTableWidget in slot?
-
I turn on editing some columns of QTableWidget by this
QObject::connect(ui->tableWidgetAdminEmployee, &QTableWidget::clicked, ui->tableWidgetAdminEmployee, [=](const QModelIndex& index) { if(index.column()!=0&&index.column()!=7&&index.column()!=8&&index.column()!=9) if (ui->tableWidgetAdminEmployee->item(index.row(), index.column())->flags() & Qt::ItemIsEnabled ) ui->tableWidgetAdminEmployee->edit(index); });But if i choose editable cell and then start editing it and press tab next cell will be selected and become editable even if it shouldn't
I turned off tabKeyNavigation in QTableWidget, but editable cells still can be selected by tab
-
Solved
for(int row=0; row<ui->tableWidgetAdminEmployee->rowCount(); row++){ for(int col=0; col< ui->tableWidgetAdminEmployee->columnCount(); col++){ auto item=new QTableWidgetItem; if(col==0 || col==7 || col==8|| col==9) item->setFlags(item->flags() & ~Qt::ItemIsEditable); //non-editable columns ui->tableWidgetAdminEmployee->setItem(row, col, item); } } ui->tableWidgetAdminEmployee->setSelectionMode(QAbstractItemView::NoSelection); ui->tableWidgetAdminEmployee->setEditTriggers(QAbstractItemView::NoEditTriggers); QObject::connect(ui->tableWidgetAdminEmployee, &QTableWidget::clicked, ui->tableWidgetAdminEmployee, [=](const QModelIndex& index) { if (ui->tableWidgetAdminEmployee->item(index.row(), index.column())->flags() & Qt::ItemIsEditable ) ui->tableWidgetAdminEmployee->edit(index); });