PDA

View Full Version : QTreeWidgetItem Problem



sujan.dasmahapatra
12th November 2009, 08:37
Friends

I have a QTreeWidget and some items in there QTreeWidgetItems.
Is there anyway to insert an item at the top of the item list.When Iam trying to insert an item at the top by

insertTopLevelItem(0, item);

The item is coming below the existing item...Its not going to the top of the list. How could I force an item to appear at the top of all the items ..

Any help would be appreaciated.

spirit
12th November 2009, 08:44
did you see notice in description of QTreeWidget::insertTopLevelItem?


If the item has already been inserted somewhere else it wont be inserted.

sujan.dasmahapatra
12th November 2009, 09:30
so how could I insert an item at the top and all other items should be increased by one and they should be rearranged ?

spirit
12th November 2009, 09:39
something like this?


QTreeWidget *treeWidget = new QTreeWidget();
treeWidget->setColumnCount(1);
QList<QTreeWidgetItem *> items;
for (int i = 0; i < 10; ++i) {
QTreeWidgetItem *parent = new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("item: %1").arg(i)));
for (int j = 0; j < 10; ++j)
new QTreeWidgetItem(parent, QStringList(QString("item: %1").arg(i)));
items.append(parent);
}
treeWidget->insertTopLevelItems(0, items);

QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("item: %1").arg(-1)));
for (int i = 0; i < 10; ++i) {
QTreeWidgetItem *parent = new QTreeWidgetItem(item, QStringList(QString("item: %1").arg(i)));
for (int j = 0; j < 10; ++j)
new QTreeWidgetItem(parent, QStringList(QString("item: %1").arg(i)));
items.append(parent);
}
treeWidget->insertTopLevelItem(0, item);

QVBoxLayout *vbl = new QVBoxLayout(this);
vbl->addWidget(treeWidget);