Solved Reading indexes in QStandardItemModel
-
Hi,
I have a QStandardItemModel displaying data in a TableView. Which is the best way to find the row and column of a cell the user clicked on?
Thank you. -
Hi!
U should use indexAt(QPoint), rowAt(int) and columnAt(int) inside overriden mousePressEvent or mouseReleaseEvent methodes. Cooridnates can be obtained from the Event class. -
@Harb
Can you please show me an example how to use them? Thank you. -
the view emits a signal with what you want already, you just need to connect it:
QAbstractItemView::clicked(const QModelIndex &index) -
Can you please show me how to read the values from index?
Thank you. -
You can ask the model
http://doc.qt.io/qt-5/qstandarditemmodel.html#itemFromIndex -
I figured it out.
void MainWindow::on_tableView_clicked(const QModelIndex &index) { int row = index.row (); int column = index.column (); qDebug() << "Index: " << "(" << row <<"," << column << ")"; }