简单的示例代码如下:
model的flag()里
Qt::ItemFlags PackageTreeModel::flags(const QModelIndex &index)const //almost done
{
if (!index.isValid())
return 0;
if (index.column() == PACKAGE_NAME)
return Qt::ItemIsTristate | Qt::ItemIsSelectable |Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
。。。。
------------
model的data()里:
QVariant PackageTreeModel::data(const QModelIndex &index, introle) const
{
if (role == Qt::CheckStateRole)
{
if (col == PACKAGE_NAME)
{return QVariant(Qt::PartiallyChecked);
。。。。。
--------
checkbox死活显示不了 Qt::PartiallyChecked 状态。我要崩溃了。网上资料实在找不到。
(但是,可以显示Qt::Checked,和Qt::Unchecked状态。)