WIth the following minimal example:

#include <QApplication>
#include <QTreeView>
#include <QStandardItemModel>
#include <QStandardItem>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    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"));
        }
    }

    QTreeView view;
    view.setModel(&model);
    view.show();
    view.resizeColumnToContents(0);

    return app.exec();
}

I get the attached result. Note how the first column does not snugly
fit the contents. The limiting factor should be the width of the
header ("Header 1"), but there's plenty of room left to shrink the
column.

Anyone else had this problem? Is there a way to improve the accuracy
of QTreeView::resizeColumnToContents ?

This is with Qt 5.5.1 (Ubuntu 16.04 package).

Thanks in advance,
Elvis
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to