From 54e43f695d347fb53aaafbbf69697f54959a7475 Mon Sep 17 00:00:00 2001 From: Elvis Stansvik Date: Thu, 2 Feb 2017 15:29:34 +0100 Subject: [PATCH] Fix header content size when sorting is disabled Summary: Instead of always adding space for the sorting indicator in item view headers, only add it if sorting is enabled. Without this fix, operations such as QTreeView::resizeColumnToContents(..) will not result in a snug fit when the header section is wider than all items in the column. Test Plan: ``` #include #include #include #include int main(int argc, char *argv[]) { QApplication app(argc, argv); // Test model QStandardItemModel model(3, 2); model.setHorizontalHeaderLabels({ "Header 1", "Header 2" }); for (int row = 0; row < 3; ++row) { for (int column = 0; column < 2; ++column) { model.setItem(row, column, new QStandardItem("Foo")); } } // View with sorting disabled QTreeView view; view.setWindowTitle("Sorting Disabled"); view.setModel(&model); view.show(); view.resizeColumnToContents(0); // View with sorting enabled QTreeView viewWithSorting; viewWithSorting.setWindowTitle("Sorting Enabled"); viewWithSorting.setModel(&model); viewWithSorting.setSortingEnabled(true); viewWithSorting.show(); viewWithSorting.resizeColumnToContents(0); return app.exec(); } ``` Notice how before applying this fix, there's space reserved for the sorting indicator even on the QTreeView that has sorting disabled. Before the fix: {F2405867} After the fix: {F2405871} Reviewers: #breeze, hpereiradacosta Reviewed By: hpereiradacosta Subscribers: hpereiradacosta, cfeck, plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D4406 --- kstyle/breezestyle.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp index a16ba54b..87288c0e 100644 --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -2926,9 +2926,9 @@ namespace Breeze int contentsHeight( headerOption->fontMetrics.height() ); if( hasIcon ) contentsHeight = qMax( contentsHeight, iconSize.height() ); - if( horizontal ) + if( horizontal && headerOption->sortIndicator != QStyleOptionHeader::None ) { - // also add space for icon + // also add space for sort indicator contentsWidth += Metrics::Header_ArrowSize + Metrics::Header_ItemSpacing; contentsHeight = qMax( contentsHeight, int(Metrics::Header_ArrowSize) ); }