View Full Version : QTreeWidget Help pls

16th March 2006, 13:06

I am inserting QTreeWidgetItem in QTreeWidget using addTopLevelItem() and also making it editable by setting appropriate flag.

How can i directly insert an Item in edit mode ?

Is there a way by which i can know that an item an gone from editmode to select mode and vice-versa?


16th March 2006, 13:26
So you want the item in edit mode right after adding it to the tree?
There is a method for starting the edit mode: QTreeWidget::editItem().

QTreeWidgetItem* item = new QTreeWidgetItem(tree);
// need to add editable flag, items are not editable by default
item->setFlags(item->flags() | Qt::ItemIsEditable);
tree->editItem(item, 0);

16th March 2006, 13:33
Thanks for replying.

Is there a way by which i can know that an item has become editable or has changed from editable to non-editable (Basically is there a way by which i can know if the user is done with his editing?)

Thanks a lot

16th March 2006, 14:39
Hrm, I couldn't find any neat way to do that.

One way I found:

class Something ...
private slots:
void setEditItem(QTreeWidgetItem* item);
void itemEditDone();
QTreeWidget* m_tree;
QTreeWidgetItem* m_item;

connect(m_tree, SIGNAL(itemChanged(QTreeWidgetItem*, int)),
this, SLOT(setEditItem(QTreeWidgetItem*)));
connect(m_tree->itemDelegate(), SIGNAL(closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint)),
this, SLOT(itemEditDone()));

void Something::setEditItem(QTreeWidgetItem* item)
// keep track of the changing item
// this gets called when items are eg. added, not only when edited...
m_item = item;

void Something::itemEditDone()
// this gets called when the actual editing is done
// currentItem() does not workie here so that's why
// keeping track of changing items :p
qDebug() << m_item->text(0);