I’m working a small qt app (using PyQt4) and I’ve come up with an idea but I’m unsure as to how to implement it. I have a QTableView that represents some data and I’d like to add another column to the QTableView that contains a checkbox control that could be wired up to some piece of the model. For example, something like this:

Note the Delete column has a checkbox widget for each row (although this is a web app, not a desktop Qt app, the principal is the same). Bonus points if I can select multiple rows, right click, and choose “Check/Uncheck Selected”.
If any of this is unclear, drop a comment here and I’ll clarify.
Implementing your own table model is more work than using
QStandardItemModel(as @Andy recommends), but it does give you a fine control over what you want to do, so I’ll try to give you a summary of what to do. I assume you know all about Qt’s documentation and PyQt’s class documentation and can look up whatever classes you need. (I may be overexplaining if you already have aQTableViewbut better than leaving something out, I think.)To get checkable states:
QTableModel.QSqlTableModelinstead).rowCount,columnCount,data, andsetData.rowCountandcolumnCountcorrespond fairly directly to what you use for a data model. If you basically are using a 2D array (or list of lists), they can be as short as one-liners.datais where things get interesting. Item models store several different fields (which Qt calls roles) and whatdatareturns depends on what role is being asked for. Note that I talk about the data types of what’s returned but it always needs to be wrapped intoQVariant.Qt.DisplayRoleis whatever text is displayed in the cells of the table. This is your actual data, and is by far the common case (so that this is the default role).Qt.CheckStateRoleis a boolean. ReturningQt.Checkedwill display a checked check-box, andQt.Uncheckedwill return an unchecked one. If all you want a column to contain is check-boxes only handle this role.QVariant.setDatais symmetric todata. You should handle the roles you handle indata:Qt.DisplayRolefor the actual data, andQt.CheckStateRolefor the checkboxes.To allow multiple selection of rows and columns and cells. To do that you want to understand selection models. The short version is:
view.setSelectionMode( QAbstractItemView.ContiguousSelection). This will let you highlight contiguous cells. You can highlight arbitrary cells as well: seeQAbstractView.SelectionMode.view.selectionModel().selectedIndexes(). You can iterate through these with aforloop.To allow right-clicking:
contextMenuEvent.QMenuand connect it to whatever slots you need.For a more in-depth understanding read the Qt guide to Model/View if you haven’t already. And definitely look at the Qt item view examples. Many of the ones describe are implemented in PyQt in much less code (including the two @Jesse mentions), and the tree model examples carry over to tables but with much less work (you need to implement much less, as described above.)