How to add manually a column to a treewidget?
-
I think it is called column.. This is a treewidget:
!http://i53.tinypic.com/2lwlrt0.jpg(Screen)!
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");@Don't know...
-
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?
!http://i53.tinypic.com/2a85ni1.jpg(sc)!Yes i know.. But there must be a way that you can add a column like ( History entries ) trough code...
-
"QTreeWidget::setColumnCount()":http://doc.qt.nokia.com/4.7/qtreewidget.html#columnCount-prop
"QTreeWidgetItem::setData()":http://doc.qt.nokia.com/4.7/qtreewidgetitem.html#setData -
I don't understand :/
@QTreeWidgetItem *itemo = new QTreeWidgetItem;
itemo->setText(QString("History Entries"));
ui->treeWidget->setHeaderItem(itemo);@?
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.
-
Hi Leon
did you look at tzhe fiunctions I pointed you to?
- QTreeWidget::setHeaderItem
- QTreeWidget::setHeaderLabel
- QTreeWidget::setHeaderLabels
[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]