Gui: Fix document tree background rendering with overlay (Qt6) #13807
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Warning
I don't have ability to build FreeCAD with Qt5 right now. So I need someone to test if this solution works with Qt5. To test it use patched OpenLight: obelisk79/OpenTheme#30
You can checkout it from your
~/.local/share/FreeCAD/Mod/OpenTheme
directory using:This aims to fix rendering of tree view items in Qt6. While I don't belive that this is a good way to fix this, I am worried that it is the only way to do it.
BC BREAK: This change introduces artificial QTreeView widget that can be targeted using QSS and can be used in the delegate for painting background of items.
QTreeView::item
would now be used to render background for the whole row, while each cell can be targeted using#DocumentTreeItems
selector.I managed to find a hacky solution to this problem. To disable rendering of the background I can abuse this if statement in Qt:
So disabling background for
::item
disables rendering of branches and not-wanted background (I'm using qtsass):This however denies me from defining background in qss. But as a workarond I create artificial QTreeView widget inside the delegate with some well defined object name,
DocumentTreeItems
in my case:Thanks to that I can attach styles to this widget inside qss:
Then I can repaint the background using style and referring to my artificial widget in the
paint
method of delegate:style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, artificial);
This gives the expected result:
I'm however deeply dissatisfied with this solution, so if anyone knows a better one I'd be glad to hear suggestions.
Fixes: #13760