diff --git a/src/ui/form/controls/tableview.cpp b/src/ui/form/controls/tableview.cpp index 26a18c50..819f1a46 100644 --- a/src/ui/form/controls/tableview.cpp +++ b/src/ui/form/controls/tableview.cpp @@ -88,6 +88,18 @@ void TableView::selectCell(int row, int column) this->scrollTo(index); } +void TableView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) +{ + QTableView::selectionChanged(selected, deselected); + + if (selected.isEmpty()) + return; + + if (!currentIndex().isValid()) { + setCurrentIndex(selected.indexes().first()); + } +} + void TableView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) { QTableView::currentChanged(current, previous); diff --git a/src/ui/form/controls/tableview.h b/src/ui/form/controls/tableview.h index 144f0ed1..486ef11b 100644 --- a/src/ui/form/controls/tableview.h +++ b/src/ui/form/controls/tableview.h @@ -28,6 +28,8 @@ public slots: void selectCell(int row, int column = 0); protected: + void selectionChanged( + const QItemSelection &selected, const QItemSelection &deselected) override; void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) override; void contextMenuEvent(QContextMenuEvent *event) override;