cpp
bool JudgeParentItemVisible(QTreeWidgetItem * pLayerItem)
{
bool bVisible = true;
QTreeWidgetItem * pParentItem = (QTreeWidgetItem *)pLayerItem->parent(); //获取父节点
if (pParentItem != NULL) //父节点不为空
{
if (pParentItem->checkState(0) == Qt::CheckState::Unchecked) //如果不可见返回false
{
bVisible = false;
return bVisible;
}
bVisible = JudgeParentItemVisible(pParentItem); //可见继续判断父节点的可见性
}
else //说明是一级节点
{
if (pLayerItem->checkState(0) == Qt::CheckState::Unchecked) //如果不可见返回false
{
bVisible = false;
}
}
return bVisible;
}