views:

793

answers:

4

I've got a QTableView for which I want to display the last column always in edit mode. (It's a QComboBox where the user should be able to always change the value.)

I think I've seen the solution in the Qt documentation, but I can't find it anymore. Is there a simple way of doing it?

I think I could archive this effect by using openPersistentEditor() for every cell, but I'm looking for a better way. (Like specifying it only one time for the whole column.)

A: 

The QAbstractItemModel::flags virtual function is called to test if an item is editable (see Qt::ItemIsEditable). Take a look at Making the Model Editable in the Model/View Programming documentation.

Judge Maygarden
I'm looking for a solution not how to make a cell editable but how to display an editor the whole time.
Georg
A: 

I can't see an easy way to do this, but you might be able to manage by using a delegate. I honestly don't know exactly how it would work, but you should be able to get something working if you try hard enough. If you get a proper delegate, you should be able to set it on a whole view, one cell of a view, or just a column or row.

Caleb Huitt - cjhuitt
A: 

There are two possibilities:

Using setIndexWidget, but Trolltech writes:

This function should only be used to display static content within the visible area corresponding to an item of data. If you want to display custom dynamic content or implement a custom editor widget, subclass QItemDelegate instead.

(And it breaks the Model/View pattern…)

Or using a delegate's paint method. But here you have to implement everything like enabled/disabled elements yourself.

Georg
+1  A: 

One way to get the automatic editing behaviour is to call the view's setEditTriggers() function with the QAbstractItemView::AllEditTriggers value.

To display the contents of a given column in a certain way, take a look at QAbstractItemView::setItemDelegateForColumn(). This will let you specify a custom delegate just for those items that need it. However, it won't automatically create an editor widget for each of them (there could in principle be thousands of them), but you could use the delegate to render each item in a way that makes it look like an editor widget.

David Boddie