From 4aabd47dcd3da8ecedcf08909065e7f0f9301f5b Mon Sep 17 00:00:00 2001 From: Kacper Donat Date: Sat, 27 Jul 2024 20:27:35 +0200 Subject: [PATCH] Gui: Trim tree view column only if one column --- src/Gui/Tree.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 4aa18f2a8c..a5cd892e6d 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -97,6 +97,11 @@ static bool isVisibilityIconEnabled() { return TreeParams::getVisibilityIcon(); } +static bool isOnlyNameColumnDisplayed() { + return TreeParams::getHideInternalNames() + && TreeParams::getHideColumn(); +} + static bool isSelectionCheckBoxesEnabled() { return TreeParams::getCheckBoxesSelection(); } @@ -478,19 +483,18 @@ void TreeWidgetItemDelegate::paint(QPainter *painter, auto tree = static_cast(parent()); auto style = tree->style(); - // If the second column is not shown, we'll trim the color background when + // If only the first column is shown, we'll trim the color background when // rendering as transparent overlay. - - bool trimBG = TreeParams::getHideColumn() || TreeParams::getHideInternalNames(); + bool trimColumnSize = isOnlyNameColumnDisplayed(); if (index.column() == 0) { if (tree->testAttribute(Qt::WA_NoSystemBackground) - && (trimBG || (opt.backgroundBrush.style() == Qt::NoBrush + && (trimColumnSize || (opt.backgroundBrush.style() == Qt::NoBrush && _TreeItemBackground.style() != Qt::NoBrush))) { QRect rect = calculateItemRect(option); - if (trimBG && opt.backgroundBrush.style() == Qt::NoBrush) { + if (trimColumnSize && opt.backgroundBrush.style() == Qt::NoBrush) { painter->fillRect(rect, _TreeItemBackground); } else if (!opt.state.testFlag(QStyle::State_Selected)) { painter->fillRect(rect, _TreeItemBackground); @@ -527,7 +531,7 @@ void TreeWidgetItemDelegate::initStyleOption(QStyleOptionViewItem *option, ); } - if (TreeParams::getHideColumn()) { + if (isOnlyNameColumnDisplayed()) { option->rect = calculateItemRect(*option); // we need to extend this shape a bit, 3px on each side