[Solved]Listview columnheaders
-
if I use a treeview could I set it in report mode (list) or could i use a tableview or something instead.
I think that the listview should be the best component for me in this case.
When i'm reading the tutorial of the listview there is a addColumn method but not when I'm trying to use it.
-
A QListView can only display a simple list, either in the form of a normal list, or in the form of a grid of icons. It can not display multiple columns. If you need multiple columns, you should use a QTableView instead. Note that both of them work with QAbstractItemModel derived model to supply the data for the view.
Edit:
Oh, and a QListView does not have headers, no matter if your model supplies them or not. -
Just typing something up:
@
QStandardItemModel* model = new QStandardItemModel(this);
model->setColumnCount(3);
QStringList headerLabels;
headerLabels<<"Foo" << "Bar" << "Baz";
model->setHorizontalHeaderLabels(headerLabels);
model->setRowCount(10);
for (int row(0); row < 10; ++row) {
for (int col(0); col < 3; ++col) {
QString text = QString("row %1 col %2).arg(row).arg(col);
QStandardItem* itm = new QStandardItem(text);
model->setItem(row, col, itm);
}
}m_ui->tableView->setModel(model);
@(typed in editor in forum, not tested as code)