BOOST_AUTO_TEST_CASE(testHeaderViewLength) { QTabWidget tw; tw.setFixedSize(200, 300); QTreeView* view = new QTreeView(&tw); view->setSortingEnabled(true); tw.addTab(view, "Bla"); QStandardItemModel* model = buildModel(view); view->setModel(model); BOOST_REQUIRE(model->columnCount() > 1); QHeaderView* header = view->header(); for (int c = 1; c < model->columnCount(); ++c) { header->hideSection(c); } tw.show(); QList sectionSizes; for (int c = 0; c < model->columnCount(); ++c) { BOOST_CHECK_EQUAL(c != 0, header->isSectionHidden(c)); sectionSizes.append(header->sectionSize(c)); } QString state = header->saveState().toHex(); header->restoreState(QByteArray::fromHex(state.toLatin1())); for (int c = 0; c < model->columnCount(); ++c) { BOOST_CHECK_EQUAL(c != 0, header->isSectionHidden(c)); BOOST_CHECK_EQUAL(sectionSizes.at(c), header->sectionSize(c)); } BOOST_REQUIRE(state == header->saveState().toHex()); }