Results 1 to 6 of 6

Thread: Custom Progress Dialog while loading QTreeWidget

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,348
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: Custom Progress Dialog while loading QTreeWidget

    Can anyone shed some brighter light on this topic please?
    I'd suggest that the way to do this is not to build the tree in the dialog constructor. A common "trick" is to start a single-shot QTimer with 0 ms timeout at the very end of the constructor. Connect the timeout() signal of the timer to a slot in your dialog class. In this slot, build your tree. The net effect of this trick is that the timer's timeout signal won't be handled until after the dialog is displayed (with an empty tree, of course). While you are building your tree, you can use a progress dialog to keep the user informed.

    Qt Code:
    1. MyDialog::MyDialog( QWidget * parent )
    2. : QDialog( parent )
    3. {
    4. // setupUi(); etc.
    5.  
    6. QTimer::singleShot( 0, this, buildTree() );
    7. }
    8.  
    9. void MyDialog::buildTree()
    10. {
    11. int nItems = totalItemsToBeAdded;
    12. QProgressDialog progress( "Building tree", QString(), 0, nItems, this (;
    13. progress.setWindowModality(Qt::WindowModal);
    14.  
    15. for ( int nItem = 0; nItem < nItems; ++nItem )
    16. {
    17. progress.setValue( nItem );
    18. // add tree widget item
    19. }
    20.  
    21. // Maybe emit a signal here if needed, or just let the user start interacting with the tree
    22. }
    To copy to clipboard, switch view to plain text mode 

    Alternatively, if you have real estate available in your dialog, you can simply put a QProgressBar in it and use that to show the load progress. After the tree is built, you can simply hide() the progress bar.

    Another slightly more complex scenario if you don't have the real estate is to use a stack widget in your dialog, one page containing the tree, the other containing the progress bar. When the dialog first comes up, the page containing the progress bar is shown; once the tree is filled, switch to the page containing the tree. This might actually cause filling the tree to be faster since it isn't visible and thus won't be constantly trying to update itself. It will simply update once, when you make it visible by switching pages.
    Last edited by d_stranz; 3rd March 2013 at 02:14.

  2. The following user says thank you to d_stranz for this useful post:

    m3rlin (4th March 2013)

Similar Threads

  1. costumize progress dialog
    By bossy in forum Newbie
    Replies: 4
    Last Post: 16th May 2012, 17:59
  2. Resize dialog as progress bar
    By migel in forum Newbie
    Replies: 3
    Last Post: 27th June 2011, 16:23
  3. Progress Bar Dialog using threads
    By dove17 in forum Newbie
    Replies: 3
    Last Post: 9th April 2010, 17:46
  4. Indicate loading in QTreeWidget
    By danc81 in forum Qt Programming
    Replies: 0
    Last Post: 11th February 2010, 17:44
  5. progress DIalog
    By mickey in forum Newbie
    Replies: 2
    Last Post: 26th July 2006, 15:30

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
  •  
Qt is a trademark of The Qt Company.