[Interest] QTreeView, QHeaderview, ResizeToContents and Interactive

Etienne Sandré-Chardonnal etienne.sandre at m4x.org
Fri Mar 17 09:18:58 CET 2017


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 <etienne.sandre at m4x.org
>:

> 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 <alexander.semke at web.de>:
>
>> 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
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170317/8a796fe3/attachment.html>


More information about the Interest mailing list