class MyModel : public QSqlQueryModel {
    Q_OBJECT
public:
    MyModel(QObject *parent = 0);
    Qt::ItemFlags flags(const QModelIndex &index) const;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
........
};
 
Qt::ItemFlags MyModel::flags(const QModelIndex &index) const {
    Qt::ItemFlags flags = QSqlQueryModel::flags(index);
    if (index.column() == aColWithCheckbox)
        flags |= Qt::ItemIsUserCheckable;
    else
        flags |= Qt::ItemIsEditable;
    return flags;
} 
 
QVariant MyModel::data(const QModelIndex &index,  int role) const {
  QVariant value = QSqlQueryModel::data(index, role);
  if (role == Qt::CheckStateRole && index.column() == aColWithCheckbox)
    return (QSqlQueryModel::data(index).toInt() != 0) ? Qt::Checked : Qt::Unchecked;
  else
    return value;
}
收藏

【转】Qt中QTableView中加入Check列实现

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
  • 2021-09-04
  • 2022-12-23
猜你喜欢
  • 2021-06-02
  • 2021-08-10
  • 2022-12-23
  • 2021-10-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案