There is no QStatusBar::addWidget() that takes an alignment as its second argument. You are giving the widgets stretch factors of 1 and 2.
Have you set an upper/lower bound on the progress bar?
If I add the widgets without a stretch factor (default 0, minimum size allocated) then I get a transient glitch when the progress bar reaches its maximum value that disappears when the value is reset. This is presumably a glitch in the progress bar's size hints. If I give both widgets a non-zero stretch the glitch goes away.
#include <QtGui>
#include <QDebug>
Q_OBJECT
public:
resize(320, 240);
barLabel
= new QLabel("Ready",
this);
barProgress->setMinimum(0);
barProgress->setMaximum(99);
statusBar()->addWidget(barProgress, 1); // or statusBar()->addWidget(barProgress)
statusBar()->addWidget(barLabel, 1); // or statusBar()->addWidget(barLabel)
value = 0;
connect(timer, SIGNAL(timeout()), SLOT(tick()));
timer->start(50);
}
public slots:
void tick() {
value = (value + 1) % 100;
barLabel
->setText
(QString("Value %1").
arg(value
));
barProgress->setValue(value);
}
private:
int value;
};
int main(int argc, char *argv[])
{
MainWindow m;
m.show();
return app.exec();
}
#include "main.moc"
#include <QtGui>
#include <QDebug>
class MainWindow: public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *p = 0): QMainWindow(p) {
resize(320, 240);
barLabel = new QLabel("Ready", this);
barProgress = new QProgressBar(this);
barProgress->setMinimum(0);
barProgress->setMaximum(99);
statusBar()->addWidget(barProgress, 1); // or statusBar()->addWidget(barProgress)
statusBar()->addWidget(barLabel, 1); // or statusBar()->addWidget(barLabel)
value = 0;
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), SLOT(tick()));
timer->start(50);
}
public slots:
void tick() {
value = (value + 1) % 100;
barLabel->setText(QString("Value %1").arg(value));
barProgress->setValue(value);
}
private:
QLabel *barLabel;
QProgressBar *barProgress;
int value;
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow m;
m.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks