View Full Version : How to get all column data from a single row with a QTableView and doubleclick

21st August 2011, 18:21
I was wondering if anyone could tell me the best way to get and display all the column data from a tableview, i currently have a model and pass it to the qtableview and i have used the doubleclick signal/slot to display a field when a column is clicked using the index. So for example if i have a 3 columns in a row "firstname" "middlename" "lastname" and i click the first firstname column in the view my slot displays the name i just clicked on with qdebug, but i need it to display all 3 fields from the row. Does anyone know the best way to make this work? Any help would be appreciated thanks.

21st August 2011, 18:31
Where do you want to display the values?

21st August 2011, 19:15
I just want to display from the console running this on linux. This is how i have the slot defined now

void MainUi::doubleClicked( QModelIndex index )
QItemSelectionModel* selmodel = MyTableView->selectionModel();
QModelIndex current = selmodel->currentIndex(); // the "current" item
QModelIndexList selected = selmodel->selectedIndexes(); // list of "selected" items

qDebug() << "current item = " << current.data();

this displays the value of the field i have clicked on. So what i need is to basically click on the first field in the column on a single row and not only display its value but also display the other 2 values in the columns next to it in the row, meaning the last 2 if this was a row of 3 columns. For now im just displaying using qDebug() in the slot.

21st August 2011, 21:29
Use QModelIndex::sibling() or QAbstractItemModel::index() to get other model indexes from the same row.

21st August 2011, 21:38
Thanks wysota