PDA

View Full Version : Hide rows from QTableView/QSqlRelationalTableModel



jiveaxe
10th November 2009, 21:16
Hi,
I have created a tableview which uses as model a QSqlRelationalTableModel and then some buttons for adding and removing records. All works good.

When I run the program the table shows all records. Is it possible to hide some rows (for example rows with a field different from a given one) and still have a working add/remove record functions (with primary key)?

Thanks

jiveaxe
11th November 2009, 09:39
I'm trying this approach: to use QSqlRecord QSqlQueryModel::record(int row) in a for loop to check each row in the table; from each row I got the content of the desired field using QVariant QSqlRecord::value(int index).

Well, this in theory because with the code below I have an empty value returned from QSqlRecord::value() and so comparison fails


for(int i = 0; i < numRows; i++) {
record = ((QSqlRelationalTableModel*)ui->scoopsTableView->model())->record(i);
if(record.value(field) != ui->articleComboBox->itemData(ui->articleComboBox->currentIndex()))
ui->scoopsTableView->hideRow(i);
}

Where is my error?

Lesiok
11th November 2009, 11:02
Why not to use QSqlTableModel::setFilter ?

jiveaxe
11th November 2009, 11:14
Very thanks, Lesiok. It worked fine.