How to add manually a column to a treewidget?
I think it is called column.. This is a treewidget:
And the text "History Entries" is the column or what is called..
I added it with the qt designer ( right click->edit items ).. But how can i add it through code.
Something like: @ui->treewidget->addcolumn(tr("History Entries");@
You basically cannot add columns to a view, but you can to the underlying model.
In a TreeWidget, you have to add QTreeWidgetItems.
You can use "QTreeWidget::setHeaderItem":http://doc.qt.nokia.com/4.7/qtreewidget.html#setHeaderItem or some similar functions.
You mean items like this?
Yes i know.. But there must be a way that you can add a column like ( History entries ) trough code...
I don't understand :/
@QTreeWidgetItem *itemo = new QTreeWidgetItem;
First i have this error
error: no matching function for call to ‘QTreeWidgetItem::setText(QString)’
Anyway i don't think that setheaderitem will add it as a column..
QTreeWidget works in such a way, that every row is a single item. In that respect, it is different from and inconsistent with QTableWidget that works with an item per cell (so a row is a series of items). That also goes for the header item. If you consult the documentation, you'll notice that QTreeWidgetItem does not have a method setText(QString), but only a setText(int, QString). That explains the error you get.
The number of columns in your QTreeWidget, can be controlled using the setColumnCount() method, as was pointed out to you before by Lukas. After increasing the column count, you can simply either use the existing header item and set the text for the column, or create new header item if there currently isn't one.
did you look at tzhe fiunctions I pointed you to?
[quote author="Gerolf" date="1311327187"]You can use "QTreeWidget::setHeaderItem":http://doc.qt.nokia.com/4.7/qtreewidget.html#setHeaderItem or some similar functions.[/quote]