How to set QTableWidget editable with a few non-editable columns, and editing by one click on cell?
-
@mpergand This worked
QObject::connect(ui->tableWidgetAdminEmployee, &QTableWidget::clicked, ui->tableWidgetAdminEmployee, [=](const QModelIndex& index) { ui->tableWidgetAdminEmployee->setCurrentIndex(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 now after making some columns editable i can't make them non-editable
-
@mpergand This worked
QObject::connect(ui->tableWidgetAdminEmployee, &QTableWidget::clicked, ui->tableWidgetAdminEmployee, [=](const QModelIndex& index) { ui->tableWidgetAdminEmployee->setCurrentIndex(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 now after making some columns editable i can't make them non-editable
-
@Kuji said in How to set QTableWidget editable with a few non-editable columns, and editing by one click on cell?:
But now after making some columns editable i can't make them non-editable
Change the flag of the item accordingly.
@mpergand I tryed this, but after clicking on the cell it's editable and then it becomes unselectable
QObject::connect(ui->tableWidgetAdminEmployee, &QTableWidget::clicked, ui->tableWidgetAdminEmployee, [=](const QModelIndex& index) { ui->tableWidgetAdminEmployee->setCurrentIndex(index); ui->tableWidgetAdminEmployee->item(index.row(), index.column())->setFlags(Qt::ItemIsSelectable); });
-
@mpergand I tryed this, but after clicking on the cell it's editable and then it becomes unselectable
QObject::connect(ui->tableWidgetAdminEmployee, &QTableWidget::clicked, ui->tableWidgetAdminEmployee, [=](const QModelIndex& index) { ui->tableWidgetAdminEmployee->setCurrentIndex(index); ui->tableWidgetAdminEmployee->item(index.row(), index.column())->setFlags(Qt::ItemIsSelectable); });
-
@mpergand cells are editable when i click on them and after that they are non-editable but write "edit: editing failed" in console
-
QObject::connect(ui->tableWidgetAdminEmployee, &QTableWidget::clicked,
Here you click on a table cell not on a button.
So what button are you talking about ? -
@Kuji said in How to set QTableWidget editable with a few non-editable columns, and editing by one click on cell?:
@mpergand this connection happens after pressing on usuall QPushButton
Where do you make this connection, where is that button, outside or inside the table ?
QObject::connect(ui->tableWidgetAdminEmployee, &QTableWidget::clicked,
doesn't respond to a button click. -
Done by disconnecting to set all non-editable
QObject::disconnect(ui->tableWidgetAdminEmployee,nullptr,nullptr,nullptr); ui->tableWidgetAdminEmployee->setEditTriggers(QAbstractItemView::NoEditTriggers);
and connect if want to make any columns editable or non-editable where editing works by one click