PDA

View Full Version : QProgressBar confusion



vermarajeev
22nd November 2006, 05:24
Hi guys,
I'm implementing a progressbar in my application called ChemTreeCanvas which inherits QMainWindow.
Something like this

ChemTreeCanvas::ChemTreeCanvas( QWidget *parent, const char *name) :
QMainWindow( parent, name )
{
//There are various other widgets
//QDockWindow
//QSplitter
//ScrollChemCanvas /*My scrollBar */
//QMultiLineEdit
//QPopupMenu
//and many many more

//I have put progressbar here
label = new QLabel( statusBar() );
statusBar()->addWidget( label, 2, TRUE );

progressbar = new QProgressBar(statusBar());
statusBar()->addWidget( progressbar, 1, TRUE );
progressbar->hide();
}

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

void ChemTreeCanvas::slotStartProgressBar()
{
progressbar->show();
if(chemTree->routeList() != NULL)
{
if(progressbar->isVisible())
{
progressbar->reset();
progressbar->setTotalSteps( chemTree->routeList()->count());
}
}
}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

vermarajeev
22nd November 2006, 08:52
Please help me.....Waiting for a reply

Thankx

jpn
22nd November 2006, 08:58
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.

vermarajeev
22nd November 2006, 10:52
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

void ChemTreeCanvas::slotStartProgressBar()
{
progressbar->show();
QMessageBox::information(0, 0, "Hello");
if(chemTree->routeList() != NULL)
{
progressbar->reset();
progressbar->setTotalSteps( chemTree->routeList()->count());
}
}
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

jpn
22nd November 2006, 12:02
Most likely you'll achieve the same result if you replace the line containing the QMessageBox::information() with line:


qApp->processEvents();


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::processEvents() during the progress but I guess it's called correctly as the progress bar advances properly, or does it?

vermarajeev
23rd November 2006, 06:11
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

//*.h file
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent=0, const char *name="MainWindow" );
~MainWindow(){}

private:
QPopupMenu* file;
QDockWindow* dockWindow;
QSplitter* splitter;
QScrollView* scrollView;
QLabel* label;
QProgressBar* progressbar;
};
//*.cpp file
MainWindow::MainWindow(QWidget *parent, const char *name)
:QMainWindow(parent, name)
{
file = new QPopupMenu(this);
menuBar()->insertItem( tr("&File"), file);
file->insertItem( tr("E&xit"), qApp, SLOT(quit()),
tr("Ctrl+Q", "Quit") );

dockWindow = new QDockWindow(this);
moveDockWindow( dockWindow, Left );
dockWindow->setHorizontallyStretchable( true );
dockWindow->setVerticallyStretchable( true );
dockWindow->setResizeEnabled( true );
dockWindow->setOrientation( Qt::Vertical );
dockWindow->setCaption( tr("Routes") );

splitter = new QSplitter(this);

scrollView = new QScrollView(splitter);

scrollView->setFrameStyle( QFrame::Box | QFrame::Raised );
scrollView->setMinimumSize( 200, 200 );

setCentralWidget(splitter);

label = new QLabel( statusBar() );
statusBar()->addWidget( label, 2, TRUE );

progressbar = new QProgressBar(statusBar());
statusBar()->addWidget( progressbar, 1, TRUE );

resize( 800, 600 );
}

//main.cpp
int main( int argc, char **argv )
{
QApplication app( argc, argv );

MainWindow mw;
app.setMainWidget( &mw );
mw.show();
return app.exec();
}

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

Thankx in advance

aamer4yu
23rd November 2006, 09:20
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 :)