Results 1 to 7 of 7

Thread: How to use QProgressBar correctly

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to use QProgressBar correctly

    Are you using a QProgressBar or a QProgressDialog? The former needs to be created, placed into a layout and shown before it is visible; the latter provides all that infrastructure for you by placing the progress bar into a dialog.

    You probably won't need to call processEvents, but if you do you don't want to call it any more often than is necessary to ensure timely progress bar updates. It's impossible to tell from the code sketch you provided where this should be - it could be just inside the while loop, just inside the outermost for loop, in the innermost for loop, or perhaps when the value of counter modulus some number equals zero. But you certainly don't want to call it every time counter gets incremented.

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

    jshafferman (15th April 2011)

  3. #2
    Join Date
    Dec 2010
    Posts
    76
    Thanks
    13
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to use QProgressBar correctly

    Thanks SixDegress! I didn't know that you had to place the QProgressBar into the layout before it was visible, this would be the reason I am not seeing it when the application starts the heavy lifting process.

    I don't think I need to use processEvents at all but if I wanted to I think if I used it on the outer while loop I would get the intended response. Thank you very much for clearing that up for me! I have used QProgressDialog before so I had assumed they worked the same only one was a dialog with options while the other had no options just the progress bar.

    Quick question however, if this is happening in MainWindow (which is sublcass of QMainWindow) do I just add it to the main layout. The MainWindow's central widget is a QSplitter so I am not sure how to do this because I want the progress bar to be centered in the main widget. Thanks for any additional help.

  4. #3
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to use QProgressBar correctly

    If you want your progress bar centered on top of the main window, I'd suggest using the QProgressDialog again. Giving it the main window as parent will start it off centered over that widget, and if you want the window blocked you can set it to be modal, or non-modal otherwise.

  5. #4
    Join Date
    Dec 2010
    Posts
    76
    Thanks
    13
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to use QProgressBar correctly

    Thanks I will go ahead and use the QProgressDialog again, is there anyway to hide the buttons on the QProgressDialog? I know I can simply not react to any signal being sent by a click but I am curious if there is a 'hide' option. Thanks again for your help!

  6. #5
    Join Date
    Dec 2010
    Posts
    76
    Thanks
    13
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to use QProgressBar correctly

    I figured out how to remove the cancel button, setCancelButton(0) removes the Cancel button

Similar Threads

  1. setBar ( QProgressBar * bar )
    By hvw59601 in forum Qt Programming
    Replies: 7
    Last Post: 29th July 2010, 00:09
  2. Using QProgressBar
    By gutiory in forum Qt Programming
    Replies: 6
    Last Post: 5th May 2010, 06:59
  3. QProgressBar + Mac OS X
    By THRESHE in forum Qt Programming
    Replies: 5
    Last Post: 14th December 2007, 13:41
  4. QProgressBar confusion
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 23rd November 2006, 09:20
  5. QProgressBar & 200%
    By Dmitry in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2006, 11:33

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.