PDA

View Full Version : QTreeWidget Help pls



munna
16th March 2006, 14:06
Hi,

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?

Thanks

jpn
16th March 2006, 14: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);

munna
16th March 2006, 14: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

jpn
16th March 2006, 15: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();
private:
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);
}