How to clear the old selected item, when new one is selected
-
I have a function that, give the selected items
void Widget::on_tableWidget_itemDoubleClicked(QTableWidgetItem *item)
When i change the item, the old item doesnt clear,
i've tried the below code, but it doesnt let me any item because it clears the selection immediately
void Widget::on_tableWidget_itemSelectionChanged() { ui->tableWidget->clearSelection(); }
What is the solution of it?
-
@suslucoder said in How to clear the old selected item, when new one is selected:
What is the solution of it?
Get selected items using https://doc.qt.io/qt-5/qtablewidget.html#selectedItems, iterate over them and call https://doc.qt.io/qt-5/qtablewidgetitem.html#setSelected on all of them except the item passed to on_tableWidget_itemDoubleClicked.
-
@jsulm im getting selected items in that way
QList<QTableWidgetItem*> MySelList = ui->tableWidget->selectedItems(); for (QTableWidgetItem* item : MySelList) { scln = QString::fromStdU16String(item->text().toStdU16String()); qDebug() << scln; }
-
@suslucoder Did you read my post?
-
@suslucoder have you tried
setSelectionMode(QAbstractItemView::SingleSelection);
on your table widget? Seems like you try to implement behaviour that's already there.https://doc.qt.io/qt-5/qabstractitemview.html#SelectionMode-enum
https://doc.qt.io/qt-5/qabstractitemview.html#selectionMode-prop