tags:

views:

197

answers:

2

I write a small database project for handling payroll records. These payroll records will be put into a tableview object for viewing. How can I search a particular record in a TableView ? Any idea, please help me.

+1  A: 

If you are using model / view paradigm, you may consider using a "match()" method, located in the QAbstractItemModel class. For example, see this code snippet:

model->match(model->index(0,0), 
             Qt::DisplayRole, 
             pattern, -1, 
             Qt::MatchContains | Qt::MatchRecursive );

This is a code, I use to locate a pattern string in the TreeView. The flags are set to locate those records, that have a "pattern" among their display role representation, the search is performed recursively through the tree (you don't need it in your TableView, I believe :) ).

SadSido
A: 

A Proxy-Model can be plugged between your (source) model and the view(s) to filter the models data. Take a look at QSortFilterProxyModel which allows to sort models rows/columns. Providing it with the right regexp for the key it will match only one item if found. You can use the proxy-model like a usual model (e.g. check rowCount) so it will update automatically and can be used in other views.

count0