[Interest] QTreeView, QHeaderview, ResizeToContents and Interactive

Alexander Semke alexander.semke at web.de
Sun Mar 19 13:09:55 CET 2017


On Samstag, 18. März 2017 10:47:12 CET Alexander Semke wrote:
> 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

I don't completely get this d->doDelayedResizeSections() in QHeaderView.cpp 
but when I put 
m_treeView->header()->resizeSections(QHeaderView::ResizeToContents);
into a slot and call it via QTimer::singleShot() it works:

void ProjectExplorer::setModel(AspectTreeModel* treeModel) {
	m_treeView->setModel(treeModel);
	QTimer::singleShot(1000, this, SLOT(resizeHeader()));
}

void ProjectExplorer::resizeHeader() {
	m_treeView->header()->resizeSections(QHeaderView::ResizeToContents);
}

What is being delayed here? I'm not quite comfortable with the fixed timer 
value and it doesn't work on my notebook for 0. Whatever is queued for 
processing here, how to wait until it's completely done?

void ProjectExplorer::setModel(AspectTreeModel* treeModel) {
	m_treeView->setModel(treeModel);
	//TODO: wait...
	m_treeView->header()->resizeSections(QHeaderView::ResizeToContents);
}

How to get this? qApp->processEvents() didn't help...

-- 
Alexander



More information about the Interest mailing list