Home Ask Login Register

Developers Planet

Your answer is one click away!

2mac February 2016

Widgets as data in QTableView

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 February 2016

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.

Post Status

Asked in February 2016
Viewed 1,905 times
Voted 8
Answered 1 times


Leave an answer

Quote of the day: live life