请教QTreeView设置样式怎么设置成每个层级的节点具有不同的样式
展开全部
[解决办法]
你要设置什么样的样式,方法可以通过mvc中的model来实现
QVariant CGradeLevelTblModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
int row = index.row();
int col = index.column();
if (role == Qt::DisplayRole)
{
return pGradeLevelTblData->data(row, col);
}
else if (role == Qt::TextAlignmentRole)
{
return Qt::AlignCenter;
}
else if (role == Qt::BackgroundColorRole)
{
if (pGradeLevelTblData->selCol == col && row == 1)
{
pGradeLevelTblData->selCol = -1;
return SELECT_COLOR;
}
}
return QVariant();
}
你要设置什么样的样式,方法可以通过mvc中的model来实现
QVariant CGradeLevelTblModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
int row = index.row();
int col = index.column();
if (role == Qt::DisplayRole)
{
return pGradeLevelTblData->data(row, col);
}
else if (role == Qt::TextAlignmentRole)
{
return Qt::AlignCenter;
}
else if (role == Qt::BackgroundColorRole)
{
if (pGradeLevelTblData->selCol == col && row == 1)
{
pGradeLevelTblData->selCol = -1;
return SELECT_COLOR;
}
}
return QVariant();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询