I am implementing QAbstractTableModel
and I would like to insert a QPushButton
in the last column of each row. When users click on this button, a new window is shown with more information about this row.
Do you have any idea how to insert the button? I know about delegating system but all examples are only about "how to edit color with the combo box"...
The model-view architecture isn't made to insert widgets into different cells, but you can draw the push button within the cell.
The differences are:
That said, here's how to do it:
Subclass QAbstractItemDelegate (or QStyledItemDelegate) and implement the
paint()
method. To draw the pushbutton control (or any other control for that matter) you'll need to use a style or theQStylePainter::drawControl()
method:Since the delegate keeps you within the model-view realm, use the views signals about selection and edits to popup your information window.
You can use
You can use
setCellWidget(row,column,QWidget*)
to set a widget in a specific cell.