We are using a QTableView with Qt 4.6.3, and need a column that only has a checkbox in each cell. We’re using a custom subclass of QAbstractTableModel as the model for the QTableView. Right now, we have a checkbox by setting the Qt::ItemIsUserCheckable flag. But we can’t figure out how to get rid of the blank textbox next to the checkbox!
How can we make the column only have a checkbox, nothing else?
Here is a solution. For this to work properly, your column should not have the
Qt::ItemIsEditableorQt::ItemIsUserCheckableflags set. This reads the boolean values fromQt::DisplayRoleand callssetData()withQt::EditRole(i.e. notQt::CheckStateRole.)