PDA

View Full Version : Locating QTableView row



waynew
7th February 2010, 02:04
I want to auto scroll to the row in a table view when the database contents of the row are known. The question is, how to link the database/model row to the view row.

scrollTo() might work ok, if I could identify the table index value from the known database row.
But I can't see how to do that.

Any ideas?

aamer4yu
7th February 2010, 06:50
You could also try if QAbstractItemView::scrollToBottom works for you.
How are you adding data from database ? Is it model or what ??

waynew
7th February 2010, 13:44
Data is already in the database. Yes, there is a model and a view.
When the user enters a field and clicks a button in the mainwindow, the slot function finds the correct database record. Then it would be nice to have the view scroll to that record.
The question is, knowing the correct database record, how to find it by index in the view?

aamer4yu
7th February 2010, 17:08
Dont you have the index from the model ?? Same will be used for view

waynew
7th February 2010, 17:53
That would be the thing... If I had it.

From the doc, it looks like this would work:



QModelIndex idx = model->indexInQuery(const QModelIndex & item);
view->selectRow(idx);


But I don't understand what the item is. How does this relate to the record data?

aamer4yu
8th February 2010, 04:53
Did you come across QAbstractItemModel::index ?

When the user enters a field and clicks a button in the mainwindow, the slot function finds the correct database record
Can you show the relevant code how you find the record from the model ? Because cant tell exactly without knowing what you are doing,, Let us know how you are using the model, how you are finding the item.

waynew
9th February 2010, 12:18
Thanks for your help. I got it working by selecting the id value (primary key) from the desired row, then



view->selectRow(id-1);