[Solved]Listview columnheaders
-
Hi
I'm trying to use Qlistview to show a list of objects.
In other programlanguages there is no problems to add/set Columnheaders and add items and subitems.But not in qt4 there is no addColumn and no addItem.
Maybe I should use another component because i want to sort the columns when I click on the columnheader
-
The model has a method to add columns.
Maybe a tree view could be also more appropriate for your aim. -
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.
-
Probably your example is outdated, I remember there was a method like the one you describe in old qt versions. Anyway, if you believe qlistview is the best for your aim, use it and deal with its model. The model has the management of columns.
-
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. -
Ok
Thank you all
Anyone that have a simple exampel of the QTableview
three columns with headers -
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)
-
It didn't work.
m_ui->tableView->setModel(model);
Error
error: ‘virtual void QTableWidget::setModel(QAbstractItemModel*)’ is privatebut when i tested it on a listview it worked but no columnheaders.
-
You were talking about a using a QTable_View_, not a QTable_Widget_. Big difference there.
-
Yes my misstake sorry
Is there a Swipe gesture in this component/widget
-
I found what i was lokking for when i tested Treeview