Results 1 to 7 of 7

Thread: QProgressBar confusion

  1. #1
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QProgressBar confusion

    Hi guys,
    I'm implementing a progressbar in my application called ChemTreeCanvas which inherits QMainWindow.
    Something like this
    Qt Code:
    1. ChemTreeCanvas::ChemTreeCanvas( QWidget *parent, const char *name) :
    2. QMainWindow( parent, name )
    3. {
    4. //There are various other widgets
    5. //QDockWindow
    6. //QSplitter
    7. //ScrollChemCanvas /*My scrollBar */
    8. //QMultiLineEdit
    9. //QPopupMenu
    10. //and many many more
    11.  
    12. //I have put progressbar here
    13. label = new QLabel( statusBar() );
    14. statusBar()->addWidget( label, 2, TRUE );
    15.  
    16. progressbar = new QProgressBar(statusBar());
    17. statusBar()->addWidget( progressbar, 1, TRUE );
    18. progressbar->hide();
    19. }
    To copy to clipboard, switch view to plain text mode 

    Now my problem is I'm unable to view the progress of progressbar if it is hidden, but if it is not hidden it shows me proper progressing and completes upto 100% starting from 0%.

    What I mean is, initially I will first hide the progressbar, then while loading any file I need to first show it(progressbar) and then once the file is loaded fully I need to hide it. But the probelm is even though I have used
    progressbar->show() in the code
    Qt Code:
    1. void ChemTreeCanvas::slotStartProgressBar()
    2. {
    3. progressbar->show();
    4. if(chemTree->routeList() != NULL)
    5. {
    6. if(progressbar->isVisible())
    7. {
    8. progressbar->reset();
    9. progressbar->setTotalSteps( chemTree->routeList()->count());
    10. }
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 
    I'm unable to see the progressbar.
    But if I dont hide the progressbar, and make it always visible it works fine. I dont understand why????????

    Can anyone help please?????

    Thankx in advance

  2. #2
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Post Re: QProgressBar confusion

    Please help me.....Waiting for a reply

    Thankx

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QProgressBar confusion

    Are you letting the application to process it's events?

    Oh and by the way, I think calling QWidget::show() and QWidget::isVisible() one after another makes QWidget::isVisible() return false because the widget hasn't received appropriate events by the time isVisible() is called. In another words, the widget won't be visible right away after calling show(). It will become visible when it receives a show event.
    J-P Nurmi

  4. #4
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProgressBar confusion

    Quote Originally Posted by jpn View Post
    Are you letting the application to process it's events?

    Oh and by the way, I think calling QWidget::show() and QWidget::isVisible() one after another makes QWidget::isVisible() return false because the widget hasn't received appropriate events by the time isVisible() is called. In another words, the widget won't be visible right away after calling show(). It will become visible when it receives a show event.
    I have removed isVisible from my code and still I get the same problem. Also I dont think that can be a problem. There is one more interesting thing, when I just put a QMessageBox in
    Qt Code:
    1. void ChemTreeCanvas::slotStartProgressBar()
    2. {
    3. progressbar->show();
    4. QMessageBox::information(0, 0, "Hello");
    5. if(chemTree->routeList() != NULL)
    6. {
    7. progressbar->reset();
    8. progressbar->setTotalSteps( chemTree->routeList()->count());
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 
    then I'm able to set the progress completely...I dont understand what is going on....

    Could you please explain what do you mean by
    Are you letting the application to process it's events?. M unable to get this line

    Please help me I'm in great problem.....

    Thankx

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QProgressBar confusion

    Most likely you'll achieve the same result if you replace the line containing the QMessageBox::information() with line:
    Qt Code:
    1. qApp->processEvents();
    To copy to clipboard, switch view to plain text mode 

    I have a feeling that it's not the ChemTreeCanvas::slotStartProgressBar() that's causing the problem. At least I can't see anything wrong with it so I suspect the actual problem is elsewhere.

    With "Are you letting the application to process it's events?" I meant that are you calling the aforementioned QApplication:rocessEvents() during the progress but I guess it's called correctly as the progress bar advances properly, or does it?
    J-P Nurmi

  6. #6
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProgressBar confusion

    Hi jpn,
    thankx for your reply,
    I have just put qApp->processEvents() in my code and it shows me the correct progressing. Thank you very much.

    Now i have some other problem.
    I want to make my progressbar's width and height small..Is that possible?????

    I have done a simple program for this but is unable to decrease the size of either progressbar ot statusbar. Here is the code
    Qt Code:
    1. //*.h file
    2. class MainWindow : public QMainWindow
    3. {
    4. Q_OBJECT
    5. public:
    6. MainWindow(QWidget *parent=0, const char *name="MainWindow" );
    7. ~MainWindow(){}
    8.  
    9. private:
    10. QPopupMenu* file;
    11. QDockWindow* dockWindow;
    12. QSplitter* splitter;
    13. QScrollView* scrollView;
    14. QLabel* label;
    15. QProgressBar* progressbar;
    16. };
    17. //*.cpp file
    18. MainWindow::MainWindow(QWidget *parent, const char *name)
    19. :QMainWindow(parent, name)
    20. {
    21. file = new QPopupMenu(this);
    22. menuBar()->insertItem( tr("&File"), file);
    23. file->insertItem( tr("E&xit"), qApp, SLOT(quit()),
    24. tr("Ctrl+Q", "Quit") );
    25.  
    26. dockWindow = new QDockWindow(this);
    27. moveDockWindow( dockWindow, Left );
    28. dockWindow->setHorizontallyStretchable( true );
    29. dockWindow->setVerticallyStretchable( true );
    30. dockWindow->setResizeEnabled( true );
    31. dockWindow->setOrientation( Qt::Vertical );
    32. dockWindow->setCaption( tr("Routes") );
    33.  
    34. splitter = new QSplitter(this);
    35.  
    36. scrollView = new QScrollView(splitter);
    37.  
    38. scrollView->setFrameStyle( QFrame::Box | QFrame::Raised );
    39. scrollView->setMinimumSize( 200, 200 );
    40.  
    41. setCentralWidget(splitter);
    42.  
    43. label = new QLabel( statusBar() );
    44. statusBar()->addWidget( label, 2, TRUE );
    45.  
    46. progressbar = new QProgressBar(statusBar());
    47. statusBar()->addWidget( progressbar, 1, TRUE );
    48.  
    49. resize( 800, 600 );
    50. }
    51.  
    52. //main.cpp
    53. int main( int argc, char **argv )
    54. {
    55. QApplication app( argc, argv );
    56.  
    57. MainWindow mw;
    58. app.setMainWidget( &mw );
    59. mw.show();
    60. return app.exec();
    61. }
    To copy to clipboard, switch view to plain text mode 

    I want my progressbar's width and height to be less but is unable to do that....
    Please help me

    Thankx in advance

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation Re: QProgressBar confusion

    try using setMinimumSize() and setMaximumSize() on progressbar.

    resize may not help as quoted in resize documentation -
    The size is adjusted if it lies outside the range defined by minimumSize() and maximumSize(). For windows, the minimum size is always at least QSize(1, 1), and it might be larger, depending on the window manager.
    hope this helps

Similar Threads

  1. QProgressbar and ... Spacebar
    By RafalR in forum Qt Programming
    Replies: 6
    Last Post: 11th September 2006, 18:40
  2. QSortFilterProxyModel signal and selection confusion
    By pascal123 in forum Qt Programming
    Replies: 1
    Last Post: 1st April 2006, 16:25
  3. setOrientation QProgressBar
    By fellobo in forum Qt Tools
    Replies: 4
    Last Post: 15th February 2006, 23:32
  4. Confusion with QPoint
    By therealjag in forum Qt Programming
    Replies: 9
    Last Post: 14th February 2006, 17:31
  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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.