After searching, there are four ways to embed check boxes in Qtableview:
The first type cannot be displayed before, and must be double-clicked/checked before it can be displayed, not applicable.
The second is relatively simple, usually in this way.
The third is only suitable for static display of static data
The fourth is suitable for expansion, in addition to embedding check boxes, you can paint () other controls, pictures and other custom styles.
The first method is: Edit the Delegate method
This method uses the overload createeditor () in the delegate to activate the Qcheckbox, which is the disadvantage of having to double-click/Select to display the CheckBox control. Generally do not meet the needs of our actual direct display. Refer to the qspinboxdelegate example in Qt.
The second method is to set the flags () function method of Qabstracttablemodel.
The third method is to set Qwidget with the method void Setindexwidget (const qmodelindex &index, *widget qcheckbox) in Qtableview.
Code: Setindexwidget (Index, new Qtextedit);
Qt Assistant wrote the items shown in a table view, like those in the other item views, is rendered and edited using standard Delegates. However, for some tasks it was sometimes useful to being able to insert widgets in a table instead. Widgets is set for particular indexes with the Setindexwidget () function, and later retrieved with Indexwidget ().
Qt Assistant wrote about Setindexwidget ()
Sets the given widget on the item at the given index, passing the ownership of the widgets to the viewport.
If index is invalid (e.g., if you pass the root index), this function would do nothing.
The given widget ' s Autofillbackground property must is set to true, otherwise the widget ' s background would be transparent, Showing both the model data and the item at the given index.
If Index widget A is replaced with index widget B, index widget a would be deleted. For example, in the code snippet below, the Qlineedit object would be deleted.
Setindexwidget (index, new Qlineedit);
...
Setindexwidget (index, new Qtextedit);
This function should is 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.
This feature should only be used to display static content for a single data item within the viewable area. If you want to display custom dynamic content or perform custom editor widgets, subclass Qitemdelegate instead.
This means that this is only suitable for the display of unchanging data, but not for doing something that will produce inserts, updates, deletions, and so on.
http://qimo601.iteye.com/blog/1538364
Four ways to embed check box checkbox in Qtableview Summary