Thomas Banderas
Thomas Banderas

Reputation: 1739

Column edit as Combo Box in QTableWidget

I have got color data in a cell. It is possible that when i double click on this cell I can edit it only by selecting value from Combo Box ?

But this combobox is not visible all the time - only when i click double time.

Questions:

  1. How to make that only one column is Editable (not all columns !)
  2. When i double click on this column QTableWidget shows QComboBox with my value to insert in this cell. - how to do it ?

Upvotes: 1

Views: 1082

Answers (1)

Arenim
Arenim

Reputation: 4237

You can do this, using custom itemDelegates.

The way to success will be:

  1. Subclass QAbstractItemDelegate, reimplement createEditor and make sure it creates combobox You love.
  2. use setItemDelegateForColumn and specify a column with your color content.

Hint: you can even customize display of your color data, not only editing!

Now, let speak about setting only one column editable. You have a choice.

Way 1. Do it at model level. Let Your model returns proper flags in flags(QModelIndex) and make only Your column editable.

Way 2. View level. In this case You should create a "dumb" itemDelegate which does not create editor at all and assign it to all other columns.

Personally, I like way 1. But this is for You to choose.

Upvotes: 1

Related Questions