Solved QTableView how to detect user click on cell
-
Looking at the list of signals for QTableView and QAbstractItemModel, I don't see any that would let me detect when the user has clicked on a cell in the table?
Is it possible to detect that? -
Hi
There is https://doc.qt.io/qt-5.15/qtableview.html#currentChanged
That tells when the current index is changed, aka user click on some cell.
or
https://doc.qt.io/qt-5.15/qabstractitemview.html#clicked -
Oh, I see now that I should really be using QTableWidget instead, which has useful signals, whereas QTableView has no signals.
-
@Publicnamer QTableWidget is a QTableView so all QTableView methods and signals are available in QTableWidget, so inheritance works.
Although QTableWidget also has new signals:
- https://doc.qt.io/qt-5.15/qtablewidget.html#cellClicked
- https://doc.qt.io/qt-5.15/qtablewidget.html#itemClicked
- https://doc.qt.io/qt-5.15/qtablewidget.html#currentItemChanged
- https://doc.qt.io/qt-5.15/qtablewidget.html#currentCellChanged
Note: Both have useful signals for your requirement.
-
@eyllanesc If you look at the documentation for QTableView, it does not list any signals:
-
@Publicnamer said in QTableView how to detect user click on cell:
it does not list any signals:
Because they're all in the base class - QAbstractItemView
-
Hi,
Depending on what you want to do, the view's selection model might also be of interest.
-
@Publicnamer It is recommended that you check https://doc.qt.io/qt-5.15/qtablewidget-members.html where all the methods and signals of QTableWidget are (together with the base classes)