expanding tree view problem
I've got a custom tree model/view. I've got a slot on the treeView called expandNonDefaultNodes(), which goes through all the nodes, and calls setExpanded( index, true ) on every node that isn't at the default value.
This behaves correctly, except I get a bunch of these warnings on the shell:
Code:
QPainter::begin: Cannot paint on a
null pixmap
QPainter::end: Painter not active, aborted
The debugger indicates that this is coming from the scrollbars.
However, if I call QTreeView's expandAll() instead, it works. What is QTreeView::expandAll() doing that I'm not? I looked at the code for expandAll(), and there's some stuff I don't understand (like d->layout(-1) ) but I am calling update(), updateGeometries() and viewport()->update().
Re: expanding tree view problem
Re: expanding tree view problem
Sure, here's the whole function:
Code:
void JasperView::expandNonDefaultNodes()
{
// If I uncomment this, I don't get the QPainter warnings
// and ALL the nodes are expanded..
//expandAll();
//return;
for (int i=0; i < mdl->rowCount( rootNdx ); ++i)
{
BlockTreeItem *item = getItem( ctrIndex );
// For binds, just expand so the fcalls are visible (for now)
BindBlockItem *bindBlock = dynamic_cast<BindBlockItem*>( item );
if (bindBlock)
{
setExpanded( ctrIndex, true );
}
// For functions, expand out any nodes with non-default values
FuncBlockItem *funcBlock = dynamic_cast<FuncBlockItem*>( item );
if (funcBlock)
{
bool anyExpandedNodes = false;
for (int j=0; j < mdl->rowCount( ctrIndex ); ++j )
{
ParamNodeItem *nodeItem = dynamic_cast<ParamNodeItem*>( getItem( nodeIndex ) );
ParamNode *node = nodeItem->block();
if (node)
{
bool shouldExpand = node->anyChangesFromDefault();
setExpanded( nodeIndex, shouldExpand );
anyExpandedNodes = anyExpandedNodes | shouldExpand;
}
}
// Expand this container if any of it's nodes
// are expanded
setExpanded( ctrIndex, anyExpandedNodes );
}
}
// these don't seem to make any difference
updateGeometries();
viewport()->update();
update();
}
I've tried replacing the setExpanded() calls with expand() but it does the same thing. I have verified that the setExpandeds actually get called.
One other little detail, I was calling this from my openFile, after I loaded the model data and did a setModel. That resulted in nothing expanding (again, expandAll works). I'm now calling it with this:
Code:
QTimer::singleShot( 0, ui.
treeView,
SLOT(expandNonDefaultNodes
()) );
And it works, but i get the warnings. Same thing if I call it from a QAction.
this is qt 4.5.0, btw.
Re: expanding tree view problem
What happens if you increase the timeout of the timer to 100ms or so?
1 Attachment(s)
Re: expanding tree view problem
Ok, so I figured it out. I had the "animated" property set, and that was causing problems. I wrapped the function with setAnimated( false ), setAnimated( true) and it works now.
In the process of figuring this out, I modified simpletreeview to exhibit the same behavior, attached if anyone's curious. I'm not sure how to file a bug report, and in any case, I've got a good workaround.
Thanks!
Joel