When Qt manages to do something with a built in function, but you can't do it manually, the best way is to look into Qt code to understand how it's done internally. Qt source is a very good way to find answers...
Into qheaderview.cpp, you may find that ResizeToContents is used inside resizeSections(). That last function calls viewSectionSizeHint, which in turn calls the view->sizeHintForColumn() Cheers, Etienne 2017-03-17 9:18 GMT+01:00 Etienne Sandré-Chardonnal <[email protected]> : > Sorry, I wrote too fast > > The proper way to get the column width ist tableView->sizeHintForColumn(i) > > So just do > > for(int i=0;i<header->count();++i) > header->resizeSection(i, qMax(header->sectionSizeHint(i), > tableView->sizeHintForColumn(i))); > > 2017-03-16 23:21 GMT+01:00 Etienne Sandré-Chardonnal < > [email protected]>: > >> Hi, >> >> You can resize the header sections programmatically after the first load. >> >> for(int i=0;i<header->count();++i) >> header->resizeSection(i, header->sectionSizeHint(i)); >> >> This should do the job. >> >> Cheers, >> >> Etienne >> >> 2017-03-16 22:27 GMT+01:00 Alexander Semke <[email protected]>: >> >>> Hi, >>> >>> I have a QTreeView where after setting the model I call header()- >>> >setResizeMode(QHeaderView::ResizeToContents) to adjust the column >>> width to >>> the content. Since I want the user to be able to resize the header >>> sections >>> manually, I call header()->setResizeMode(QHeaderView::Interactive) >>> after this >>> which squeezes the columns to the sizes where the content is not fully >>> visible >>> anymore. In my model in headerData() I don't calculate any sizes for the >>> SizeHintRole case. >>> >>> How can I achieve this behaviour (tree view columns automatically >>> adjusted to >>> the content after the initial load and manually resizable later) in the >>> most >>> easiest way? >>> >>> -- >>> Alexander >>> _______________________________________________ >>> Interest mailing list >>> [email protected] >>> http://lists.qt-project.org/mailman/listinfo/interest >>> >> >> >
_______________________________________________ Interest mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/interest
