Alexhuszagh / BreezeStyleSheets

Breeze/BreezeDark-like Qt StyleSheets
MIT License
548 stars 128 forks source link

[QUESTION] Remove guidings from QTreeWidget #70

Closed felipefarinon closed 1 year ago

felipefarinon commented 1 year ago

Question

Is there a way to hide the guidings from QTreeWidget, but still leave the arrows that expand/collapse items? In other words, leave them like in native Windows.

guidings

Alexhuszagh commented 1 year ago

Yes, this would be doable by changing the QTreeView:branch styles using an extension for border-image (basically, override all the branch lines so they don't exist) from to:

QTreeView::branch:has-siblings
{
    border-image: none;
    image: none;
}

/* These branch indicators don't scale */
QTreeView::branch:!has-siblings
{
    border-image: none;
    image: none;
}

QTreeView::branch:has-siblings:adjoins-item
{
    border-image: none;
}

QTreeView::branch:!has-children:!has-siblings:adjoins-item
{
    border-image: none;
}

QTreeView::branch:has-children:!has-siblings:closed,
QTreeView::branch:closed:has-children:has-siblings
{
    image: url(^style^branch_closed.svg);
}

QTreeView::branch:has-children:!has-siblings:closed:hover,
QTreeView::branch:closed:has-children:has-siblings:hover
{
    image: url(^style^branch_closed_hover.svg);
}

QTreeView::branch:has-children:!has-siblings:closed,
QTreeView::branch:open:has-children:!has-siblings
{
    border-image: none;
}

QTreeView::branch:closed:has-children:has-siblings,
QTreeView::branch:open:has-children:has-siblings
{
    border-image: none;
}

QTreeView::branch:open:has-children:!has-siblings,
QTreeView::branch:open:has-children:has-siblings
{
    image: url(^style^branch_open.svg);
}

QTreeView::branch:open:has-children:!has-siblings:hover,
QTreeView::branch:open:has-children:has-siblings:hover
{
    image: url(^style^branch_open_hover.svg);
}

Note I wouldn't do this by default, so I'd add an objectName and then have your widgets using said object name.

QTreeView[objectName="nobranch"]::branch:has-siblings
{
    border-image: none;
    image: none;
}

/* These branch indicators don't scale */
QTreeView[objectName="nobranch"]::branch:!has-siblings
{
    border-image: none;
    image: none;
}

QTreeView[objectName="nobranch"]::branch:has-siblings:adjoins-item
{
    border-image: none;
}

QTreeView[objectName="nobranch"]::branch:!has-children:!has-siblings:adjoins-item
{
    border-image: none;
}

QTreeView[objectName="nobranch"]::branch:has-children:!has-siblings:closed,
QTreeView[objectName="nobranch"]::branch:closed:has-children:has-siblings
{
    image: url(^style^branch_closed.svg);
}

QTreeView[objectName="nobranch"]::branch:has-children:!has-siblings:closed:hover,
QTreeView[objectName="nobranch"]::branch:closed:has-children:has-siblings:hover
{
    image: url(^style^branch_closed_hover.svg);
}

QTreeView[objectName="nobranch"]::branch:has-children:!has-siblings:closed,
QTreeView[objectName="nobranch"]::branch:open:has-children:!has-siblings
{
    border-image: none;
}

QTreeView[objectName="nobranch"]::branch:closed:has-children:has-siblings,
QTreeView[objectName="nobranch"]::branch:open:has-children:has-siblings
{
    border-image: none;
}

QTreeView[objectName="nobranch"]::branch:open:has-children:!has-siblings,
QTreeView[objectName="nobranch"]::branch:open:has-children:has-siblings
{
    image: url(^style^branch_open.svg);
}

QTreeView[objectName="nobranch"]::branch:open:has-children:!has-siblings:hover,
QTreeView[objectName="nobranch"]::branch:open:has-children:has-siblings:hover
{
    image: url(^style^branch_open_hover.svg);
}

If you want this by default, feel free to change it in stylesheet.qss.in and configure it as described in the README. Does that answer the question?

Alexhuszagh commented 1 year ago

I edited the above post to mention you need to keep the images: I'm currently on a work machine without access to PyQt6 so I'm denoting the actual items from memory, and there might be slight discrepancies.

felipefarinon commented 1 year ago

Yes, it answers perfectly. Thanks for that.

Alexhuszagh commented 1 year ago

I'll provide a working demo after work and then close this. I should probably add an example also, since this is a pretty common feature but not necessarily a default for all cases.

Alexhuszagh commented 1 year ago

I've added an example under branchless which contains a full, working example with images of the result. I presume this is the desired result?

Dark

Light

felipefarinon commented 1 year ago

It's exactly that. Thanks!