我想在中实现用户可编辑复选框QTableView
它是使用 QAbstractModel 创建的。我可以分配选中和未选中的复选框,但无法使其可编辑。
标志设置为QItemIsUserCheckable
.
您可以通过实施模型轻松做到这一点setData()
像这样的方法:
bool yourModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!index.isValid())
return false;
if (role == Qt::CheckStateRole)
{
if ((Qt::CheckState)value.toInt() == Qt::Checked)
{
//user has checked item
return true;
}
else
{
//user has unchecked item
return true;
}
}
return false;
}
并且不要忘记您的模型data()
method:
QVariant ProxyModelSubobjects::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role == Qt::CheckStateRole && index.column() == COLUMN_WITH_CHECKBOX)
{
//return Qt::Checked or Qt::Unchecked here
}
//...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)