PDA

View Full Version : QSqlTableModel remove column by name



qlands
5th July 2011, 09:30
Hi,

I have a QSqlTableModel reading a table with 5 fields but I just want to display 1. Because I don't know the order of the fields (ie which one is 1 or 2 or 3, etc) I need to remove them by name. I can see that there is model->removeColumn(int) but How Can it remove them by name?

Thanks,
Carlos.

mcosta
5th July 2011, 10:49
If you only need to NOT show column data, you don't need remove columns, you only have to "hide" the column.

With QSqlTableModel::findIndex() you can find the column index, then you can use QTableView::hideColumn() to hide desired column.

qlands
5th July 2011, 13:48
Excellent! Thanks.