PDA

View Full Version : [SOLVED]QTreeWidget doesn't want to be edited



grabalon
27th July 2010, 18:01
Hey,

I'm using Qt Creator to develop my app, and have a dialog containing a QTreeWidget. I populate it by querying a local database for record names. I can give the code for populating it, but I'm pretty sure I don't set any properties of the TreeWidget from there. Suffice it to say that I have Parents and Children being populated.

I would like to allow my users to change parent names, but I can't get the Tree to accept a double click as an edit. Instead it treats double click as "Expand Children". I have the following call in the constructor of the dialog

ui.flightSearchTree->setEditTriggers(QAbstractItemView::DoubleClicked);

but to no avail.

Any help is appreciated.:confused::confused:

norobro
27th July 2010, 21:26
I'm pretty sure I don't set any properties of the TreeWidget from there.That's what you need to do. By default a QTreeWidgetItem is not editable (docs (http://doc.trolltech.com/4.6/qtreewidgetitem.html#flags)) so you need to set the flag:
item->setFlags(item->flags() | Qt::ItemIsEditable);

grabalon
27th July 2010, 21:36
That did it, thanks.

As a followup, as best I can tell, the QTreeWidgetItem doesn't emit any signals, where would I connect to handle pushing the new name back into the database?

Lykurg
27th July 2010, 21:39
Cant you use a QTreeView with a proper model? That will simplify things a lot.

grabalon
27th July 2010, 21:51
That will simplify things a lot.

Perhaps, but the conversion process at this point is not simple.

norobro
27th July 2010, 22:29
where would I connect to handle pushing the new name back into the database?Maybe in a custom delegate? By reimplementing setModelData() to update your DB.

grabalon
27th July 2010, 23:42
Posted for benefit of future readers:

QTreeWidget::itemChanged(QTreeWidgetItem*, int)

This signal solved my problems, but be sure to disconnect it if repopulating the QTreeWidget or you get some hyper signal emissions.