[Solved]Listview columnheaders
-
wrote on 11 Oct 2011, 06:01 last edited by
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
-
wrote on 11 Oct 2011, 06:26 last edited by
The model has a method to add columns.
Maybe a tree view could be also more appropriate for your aim. -
wrote on 11 Oct 2011, 06:31 last edited by
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.
-
wrote on 11 Oct 2011, 06:34 last edited by
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.
-
wrote on 11 Oct 2011, 06:38 last edited by
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. -
wrote on 11 Oct 2011, 07:04 last edited by
Ok
Thank you all
Anyone that have a simple exampel of the QTableview
three columns with headers -
wrote on 11 Oct 2011, 07:44 last edited by
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)
-
wrote on 11 Oct 2011, 08:17 last edited by
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.
-
wrote on 11 Oct 2011, 08:41 last edited by
You were talking about a using a QTable_View_, not a QTable_Widget_. Big difference there.
-
wrote on 11 Oct 2011, 08:47 last edited by
Yes my misstake sorry
Is there a Swipe gesture in this component/widget
-
wrote on 11 Oct 2011, 09:23 last edited by
I found what i was lokking for when i tested Treeview
1/11