Unsolved Hiding a column in QTableView
-
i am trying to populate TableView from a standardItemModel. I am done till this part. Now i am trying to Hide a particular column. Even after using hideColumn(1) or setColumnHidden(1), the columns are still visible. Any support why is it so?
-
Do you reset the model or call insert/remove columns after hiding?
-
Hi @gaurav118 ,
show the code where you got problem. -
@VRonin I am not doing any reset or deletion of column
-
@Prince_0912 here is the code snippet
ui->tableView->setModel(_itemModel);
populateItemModel();
ui->tableView->setColumnHidden(1,true); -
can you show us the content of
populateItemModel();
? -
@gaurav118 This code is right but in populateItemModel(); method some issue i think.
-
@VRonin I am not maintaining that routine. populateItemModel() is filling StandardItemModel which is working fine.
-
@Prince_0912 the tableView is not being reffered into that routine at all
-
@gaurav118 Your problem is like this i think,
https://forum.qt.io/topic/3399/solved-update-qtableview-after-hiding-columns -
this simple example should work:
#include <QApplication> #include <QTableView> #include <QStandardItemModel> int main(int argc, char *argv[]) { QApplication application(argc, argv); // prepare a dummy table model QStandardItemModel tableModel; tableModel.insertRows(0, 5); tableModel.insertColumns(0, 3); for (int i = 0; i < tableModel.rowCount(); ++i) { for (int j = 0; j < tableModel.columnCount(); ++j) { tableModel.setData(tableModel.index(i, j), QStringLiteral("Row: %1, Col: %2").arg(i).arg(j)); } } QTableView sourceTableView; sourceTableView.setModel(&tableModel); sourceTableView.setColumnHidden(1,true); sourceTableView.show(); return application.exec(); }
Can you identify what that does differently from you?