[Interest] QTreeView, QHeaderview, ResizeToContents and Interactive
Alexander Semke
alexander.semke at web.de
Sat Mar 18 10:47:12 CET 2017
On Freitag, 17. März 2017 09:18:58 CET Etienne Sandré-Chardonnal wrote:
> 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)));
It's QTreeView in my case, not QTableView, but anyway. sizeHintForColumn is
protected. Your example should be equivalent to my
for (int i = 0; i<m_treeView->header()->count(); ++i)
m_treeView->resizeColumnToContents(i);
which I already tried. This only resizes one of the columns properly
http://imgur.com/a/klXS8
> 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...
Yes, that's true. I checked already the source code and I just don't see at
the moment what I'm doing wrong here. What I don't understand neither is that
when doing
m_treeView->resizeColumnToContents(0);
right after I set my model via m_treeView->setModel(my_model); like in the
loop above, the first column is not resized properly. But when I call this
later when the user adds new objects to the data model and I want to adjust
the first column to the new name, the first columnt with the object names is
adjusted as expected:
http://imgur.com/a/JRI4z
Here, Worksheet1 was added and there is a
m_treeView->resizeColumnToContents(0);
again in the corresponding slot that handles newly added objects.
This must be something trivial that I'm missing at the moment. I just don't
see it and it blocks the next release of LabPlot at the moment :-(
--
Alexander
More information about the Interest
mailing list