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 <QApplication>
#include <QTreeView>
#include <QStandardItemModel>
#include <QStandardItem>
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