Results 1 to 5 of 5

Thread: expanding tree view problem

  1. #1
    Join Date
    Apr 2006
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default 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:

    Qt Code:
    1. QPainter::begin: Cannot paint on a null pixmap
    2. QPainter::translate: Painter not active
    3. QPainter::end: Painter not active, aborted
    To copy to clipboard, switch view to plain text mode 

    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().

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: expanding tree view problem

    Can we see your code?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2006
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: expanding tree view problem

    Sure, here's the whole function:

    Qt Code:
    1. void JasperView::expandNonDefaultNodes()
    2. {
    3. // If I uncomment this, I don't get the QPainter warnings
    4. // and ALL the nodes are expanded..
    5. //expandAll();
    6. //return;
    7.  
    8. QAbstractItemModel *mdl = model();
    9. QModelIndex rootNdx = rootIndex();
    10.  
    11. for (int i=0; i < mdl->rowCount( rootNdx ); ++i)
    12. {
    13. QModelIndex ctrIndex = mdl->index( i, 0, rootNdx );
    14. BlockTreeItem *item = getItem( ctrIndex );
    15.  
    16. // For binds, just expand so the fcalls are visible (for now)
    17. BindBlockItem *bindBlock = dynamic_cast<BindBlockItem*>( item );
    18. if (bindBlock)
    19. {
    20. setExpanded( ctrIndex, true );
    21. }
    22.  
    23. // For functions, expand out any nodes with non-default values
    24. FuncBlockItem *funcBlock = dynamic_cast<FuncBlockItem*>( item );
    25.  
    26. if (funcBlock)
    27. {
    28. bool anyExpandedNodes = false;
    29. for (int j=0; j < mdl->rowCount( ctrIndex ); ++j )
    30. {
    31. QModelIndex nodeIndex = mdl->index( j, 0, ctrIndex );
    32. ParamNodeItem *nodeItem = dynamic_cast<ParamNodeItem*>( getItem( nodeIndex ) );
    33. ParamNode *node = nodeItem->block();
    34.  
    35. if (node)
    36. {
    37. bool shouldExpand = node->anyChangesFromDefault();
    38. setExpanded( nodeIndex, shouldExpand );
    39.  
    40. anyExpandedNodes = anyExpandedNodes | shouldExpand;
    41. }
    42. }
    43.  
    44. // Expand this container if any of it's nodes
    45. // are expanded
    46. setExpanded( ctrIndex, anyExpandedNodes );
    47.  
    48. }
    49. }
    50.  
    51. // these don't seem to make any difference
    52. updateGeometries();
    53. viewport()->update();
    54. update();
    55. }
    To copy to clipboard, switch view to plain text mode 

    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:

    Qt Code:
    1. QTimer::singleShot( 0, ui.treeView, SLOT(expandNonDefaultNodes()) );
    To copy to clipboard, switch view to plain text mode 

    And it works, but i get the warnings. Same thing if I call it from a QAction.

    this is qt 4.5.0, btw.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: expanding tree view problem

    What happens if you increase the timeout of the timer to 100ms or so?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Apr 2006
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default 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
    Attached Files Attached Files

Similar Threads

  1. QGraphics view problem
    By kiranraj in forum Qt Programming
    Replies: 5
    Last Post: 6th March 2007, 21:28
  2. graphics view FitInView problem
    By aamer4yu in forum Qt Programming
    Replies: 6
    Last Post: 25th January 2007, 10:24
  3. data, model and tree view
    By larry104 in forum Qt Programming
    Replies: 17
    Last Post: 3rd July 2006, 14:43
  4. problem with tree view
    By boss_bhat in forum Newbie
    Replies: 4
    Last Post: 4th June 2006, 21:03
  5. View update problem
    By prakash in forum Qt Programming
    Replies: 6
    Last Post: 17th March 2006, 10:13

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.