首页 前端知识 Qt——简单树形控件样式设计(QTreeWidget)

Qt——简单树形控件样式设计(QTreeWidget)

2024-02-19 09:02:55 前端知识 前端哥 730 691 我要收藏
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); //初始状态没有被选中

转载请注明出处或者链接地址:https://www.qianduange.cn//article/2264.html
标签
pyqt
评论
发布的文章

jquery初始化方法

2024-03-04 10:03:13

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!