狀態欄顯示的信息分3種
1. 一般信息,用QLabel 代表
2. 永久信息,文本會一直顯示在狀態欄的最右邊。
3. 臨時信息,指定信息現實的時間。時間到即信息消失
QLabel *locationLabel; locationLabel = new QLabel("July"); locationLabel->setAlignment(Qt::AlignCenter); locationLabel->setMinimumSize(locationLabel->sizeHint()); QLabel *aixLabel; aixLabel = new QLabel("\"CTRL + H\" for help"); //Optional statusBar()->setStyleSheet(QString("QStatusBar::item{border: 0px}")); // 設置不顯示label的邊框 statusBar()->setSizeGripEnabled(false); //設置是否顯示右邊的大小控制點 statusBar()->addWidget(locationLabel); statusBar()->addWidget(aixLabel, 1); QLabel *per1 = new QLabel("Ready1", this); QLabel *per2 = new QLabel("Ready2", this); QLabel *per3 = new QLabel("Ready3", this); statusBar()->addPermanentWidget(per1); //現實永久信息 statusBar()->addPermanentWidget(per2); statusBar()->insertPermanentWidget(2, per3); statusBar()->showMessage("Status is here...", 3000); // 顯示臨時信息,時間3秒鍾.
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); // QLabel *normal=new QLabel("正常信息",this); // ui->statusBar->addWidget(normal);//顯示正常信息 ui->statusBar->setSizeGripEnabled(false);//去掉狀態欄右下角的三角 ui->statusBar->showMessage(tr("臨時信息!"),2000);//顯示臨時信息2000ms 前面的正常信息被覆蓋 當去掉后一項時,會一直顯示 QLabel *permanent=new QLabel(this); permanent->setFrameStyle(QFrame::Box|QFrame::Sunken); permanent->setText(tr("<a href=\"http://tengweitw.ueuo.com\">永久信息</a>")); permanent->setOpenExternalLinks(true);//設置可以打開網站鏈接 ui->statusBar->addPermanentWidget(permanent);//顯示永久信息
【參考:】