How to set QTableWidget editable with a few non-editable columns, and editing by one click on cell?
-
@JonB Added, when i choose cell which is non-editable console writes:
In slot
Calling edit()
edit: editing failed
Called edit()When i choose editable cells console writes:
In slot
Calling edit()
Called edit()@Kuji said in How to set QTableWidget editable with a few non-editable columns, and editing by one click on cell?:
@JonB Added, when i choose cell which is non-editable console writes:
I did not realize you were doing this on the non-editable cells! So it is behaving well/as it should, what is the issue? Earlier you wrote:
but when i click on enabled cell in console appears line "edit: editing failed"
Now you show that works fine on editable cells.
-
How can i get rid of lines in console:edit: editing failed? By don't calling edit() for these cells then how exclude these cells?
-
if (ui->tableWidgetAdminEmployee->itemFromIndex(index)->flags() & Qt::ItemIsEnabled ) ui->tableWidgetAdminEmployee->edit(index);
Something like that.
-
@JonB Can't write instead of this code line because of en error, or i should write this in another place?
ui->tableWidgetAdminEmployee->edit(index);
@Kuji said in How to set QTableWidget editable with a few non-editable columns, and editing by one click on cell?:
Can't write instead of this code line because of en error,
Then fixing the error would be a good start.
-
@Kuji said in How to set QTableWidget editable with a few non-editable columns, and editing by one click on cell?:
Can't write instead of this code line because of en error,
Then fixing the error would be a good start.
@Christian-Ehrlicher i mean this error
error: 'itemFromIndex' is a protected member of 'QTableWidget'
here
QObject::connect(ui->tableWidgetAdminEmployee, &QTableWidget::clicked, ui->tableWidgetAdminEmployee, [=](const QModelIndex& index) { ui->tableWidgetAdminEmployee->setCurrentIndex(index); if (ui->tableWidgetAdminEmployee->itemFromIndex(index)->flags() & Qt::ItemIsEnabled ) ui->tableWidgetAdminEmployee->edit(index); });
-
@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