我正在开发一个项目(大而复杂),我必须使用CSS和c ++重新设计样式。
对于这个项目,有一个自定义QTreeWidget,必须如下所示:
问题是,当我将鼠标悬停在某个项目上时,如何更改“箭头”/指示符的悬停背景颜色?这是设计师的要求 正如你在图片中看到我悬停项目时我可以改变背景颜色,当我将鼠标悬停在箭头上时我可以改变背景颜色。但是我如何能够在整个行中实现徘徊?
所以我想要的就是这个。当我将鼠标悬停在一个项目上时,分支的悬停会随着项目的变化而变化。当我只悬停分支时只更改箭头图标。
这是用于设置treewidget样式的css代码;
XProjectTreeWidget {
background-color: rgb(85, 85, 85);
border: none;
font-size: 14px;
padding-left: 16px;
outline: 0px;
}
XProjectTreeWidget::item {
color: rgb(255, 255, 255);
min-height: 50px;
border-bottom :2px solid qlineargradient(x1:0, y1:0, x2:0, y2:1, stop: 0.48 rgb(34, 34, 34), stop: 0.5 rgb(134, 134, 134));
}
XProjectTreeWidget::item::hover {
background-color: rgb(101, 101, 101);
}
XProjectTreeWidget::item QLineEdit {
border: none;
min-height: 18px;
max-height: 18px;
min-width: 80px;
padding: 0px;
}
XProjectTreeWidget QHeaderView::section {
background-color: rgb(85, 85, 85);
color: rgb(255, 255, 255);
border-top: 0px;
border-left: 0px;
border-right: 0px;
border-bottom :2px solid qlineargradient(x1:0, y1:0, x2:0, y2:1, stop: 0.48 rgb(34, 34, 34), stop: 0.5 rgb(134, 134, 134));
font-size: 20px;
padding-left: 4px;
}
XProjectTreeWidget:disabled QHeaderView::section:disabled {
color: rgb(200, 200, 200);
}
XProjectTreeWidget::branch:has-children:!has-siblings:closed,
XProjectTreeWidget::branch:closed:has-children:has-siblings {
border-bottom :2px solid qlineargradient(x1:0, y1:0, x2:0, y2:1, stop: 0.48 rgb(34, 34, 34), stop: 0.5 rgb(134, 134, 134));
image: url(:/theme/dark/expanderRightArrowActive);
}
XProjectTreeWidget::branch:open:has-children:!has-siblings,
XProjectTreeWidget::branch:open:has-children:has-siblings {
border-bottom :2px solid qlineargradient(x1:0, y1:0, x2:0, y2:1, stop: 0.48 rgb(34, 34, 34), stop: 0.5 rgb(134, 134, 134));
image: url(:/theme/dark/expanderDownArrowActive);
}
XProjectTreeWidget {
background-color: rgb(85, 85, 85);
}
由于此应用程序的代码非常复杂,因此不能使用代理从QTreeWidget更改为QTreeView。
我找到了感兴趣的任何人的溶剂。
你必须在你的QtreeWidget QtreeView上设置它
QTreeView, QTreeWidget {
show-decoration-selected: 1;
}
QTreeView::branch {
background-color: rgb(same color as the item);
}
QTreeView::branch:selected {
background-color: rgb(same color as the item);
}
QTreeView::branch:!selected {
background-color: rgb(same color as the item);
}
QTreeView::branch:hover {
background-color: rgb(same color as the item hover);
}
QTreeView::branch:!has-children{
/*this is for hovering only the barnch and not the entire row*/
background-color: rgb(same color as the item);
}