Qt学习之路 —QStatusBar

August 5th, 2013 by JasonLe's Tech Leave a reply »

QStatusBar 与 QToolBar 很类似

mProbar = new QProgressBar(this);
mLabel = new QLabel(“Hello World”,this,0);
ui->statusBar->addPermanentWidget(mProbar,1);
ui->statusBar->addPermanentWidget(mLabel);
mProbar->setTextVisible(false);

以上代码的addPermanentWidget函数是从左到右的添加,是有先后顺序的。另外addPermanentWidget()第二个参数可以设置控件长度。

void QStatusBar::addPermanentWidget(QWidget * widget, int stretch = 0)

Adds the given widget permanently to this status bar, reparenting the widget if it isn’t already a child of thisQStatusBar object. The stretch parameter is used to compute a suitable size for the given widget as the status bar grows and shrinks. The default stretch factor is 0, i.e giving the widget a minimum of space.

Permanently means that the widget may not be obscured by temporary messages. It is is located at the far right of the status bar.