2

I'm trying to make a table-based interface as follows:

| QComboBox | QPushButton | Empty       |
| Some data | Some data   | QPushButton |
| Some data | Some data   | Empty       | (all additional rows resemble this one)

In the first row, I want a QComboBox with some selections that are defined based on the return value of another function, and the QPushButtons are attached to triggers which will insert or remove data.

Assuming I can generate the QComboBox and QPushButtons on my own, how can I get them to be inserted into the QTableView in those locations? I currently have a model which properly stores the data that need to be shown in the locations marked "Some data" and to return no data for the special or "Empty" locations, and I have a QStyledItemDelegate which is supposed to insert these widgets for me, but it only inserts them when I double click the field (which I suppose is the trigger for createEditor).

2mac
  • 1,609
  • 5
  • 20
  • 35
  • Related: http://stackoverflow.com/questions/30457935/pyqt4-adding-combobox-in-qtableview/30460687#30460687 – Andy Feb 08 '16 at 15:00

1 Answers1

1

Figured it out.

QAbstractItemView (and by extension QTableView) have a method called setIndexWidget which can be used to place a widget in a location. By using that method, I can insert the appropriate widgets on initialization without relying on a delegate at all.

2mac
  • 1,609
  • 5
  • 20
  • 35