QTreeWidget#treeWidget {
background: #F9F9F9;
border-right: 1px solid #D3D6DD;
outline: none;
font-size: 16px;
}
QTreeWidget::item {
height: 40px;
font-weight: 400;
color: #4D4D4D;
border: 0px;
outline: 0px;
font-size: 16px;
}
QTreeWidget::item:hover {
border: 0px;
outline: 0px;
color: #45B2FF;
}
QTreeWidget::item:selected{
border: 0px;
outline: 0px;
color: #45B2FF;
}
QTreeWidget::item:selected:active{
border: 0px;
outline: 0px;
color: #45B2FF;
}
QTreeWidget::item:selected:!active {
border: 0px;
outline: 0px;
color: #45B2FF;
}
QTreeWidget::branch {
height: 28px;
width: 28px;
}
QTreeWidget::branch:closed:has-children:!has-siblings,
QTreeWidget::branch:closed:has-children:has-siblings {
border-image: none;
image: url(:/images/tree_open.png);
}
QTreeWidget::branch:open:has-children:!has-siblings,
QTreeWidget::branch:open:has-children:has-siblings {
border-image: none;
image: url(:/images/tree_close.png);
}
/* QTreeWidget::branch:!has-children:has-siblings:adjoins-item{ */
/* border-image:none; */
/* image:url(:/images/tree_close.png); */
/* } */
/* QTreeWidget::branch:!has-children:!has-siblings:adjoins-item{ */
/* border-image:none; */
/* image:url(:/images/tree_close.png); */
/* } */
QTreeWidget::indicator {
height: 20px;
width: 20px;
}
QTreeWidget::indicator:checked {
image: url(:/images/select_item.png);
color: #45B2FF;
}
QTreeWidget::indicator:unchecked {
image: url(:/images/select_item_no.png);
color: #45B2FF;
}
效果图如下:
需要图中虚线连接方法1:
ui->treeWidget->setStyle(QStyleFactory::create("windows"));
方法2:
通过拼接线段图片设置样式制作(如有侵权请联系删除)
如果需要添加复选框则代码设置:
pItem1_1_1->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); //设置树形控件子项的属性 pItem1_1_1->setCheckState(0, Qt::Unchecked); //初始状态没有被选中