4

Im working on a project (big and complex) that i have to re-style using CSS and c++.

For this project there is a custom QTreeWidget that must look like this:

enter image description here

The question is, how i can change the hover background color of the "arrow"/ indicator, branch when i hover over an item? This is the designer requirement As you can see in the picture when i hover the item i can change the background-color, also when i hover over the arrow i can change the background-color. But how i can achieve the hovering over the whole row?

So what i want is this. when i hover over an item the hovering of the branch changes together with the item hovered. When i hover only the branch change only the arrow icon.

This is the css code used to style the treewidget;

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);
}

changing from QTreeWidget to QTreeView with delegates is not an option due to very complex code that this app has.

I found the sollution for anyone interested.

you have to set this on your 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);
}

0 Answers0