Hiding a column in QTableView
-
Hi @gaurav118 ,
show the code where you got problem. -
Hi @gaurav118 ,
show the code where you got problem.@Prince_0912 here is the code snippet
ui->tableView->setModel(_itemModel);
populateItemModel();
ui->tableView->setColumnHidden(1,true); -
@Prince_0912 here is the code snippet
ui->tableView->setModel(_itemModel);
populateItemModel();
ui->tableView->setColumnHidden(1,true); -
@Prince_0912 here is the code snippet
ui->tableView->setModel(_itemModel);
populateItemModel();
ui->tableView->setColumnHidden(1,true);@gaurav118 This code is right but in populateItemModel(); method some issue i think.
-
@gaurav118 This code is right but in populateItemModel(); method some issue i think.
@Prince_0912 the tableView is not being reffered into that routine at all
-
@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?