View Full Version : Button in TreeWidgetItem

15th June 2009, 13:11

I use a QTreeWidget to display a list with multiple columns (replacement of the Q3ListView).

It has to be possible to change the content of one of the columns (a dilaog has to be appear).

Now, the user can click the cell and the dialog appears, but the user has to know that, otherwise he does not know how to change the content.

That's why I'd like to insert a button at the end of this column, similar to dialogs of MS Visual Studio for example (see attachement).

The QTreeWidgetItem has only a setICon() method, I need something like a setWidget() method.

What would be an easy way to bring that button into the item?

15th June 2009, 13:24
Hi osiris81,

You can use the QItemDelegate class to create your own editor widget for the QTableWidget.

You can check the Spin Box Delegate Example.


16th June 2009, 12:55
Thank you alisami!

I tried the example and it looks good, just one thing:

The item changes it's view only when I activate it (by doubleclicking for example). Is it possible to show the item always in this "state"?

16th June 2009, 12:58
Sorry, I just found it:

void openPersistentEditor ( const QModelIndex & index )