[轉]Qt狀態欄(statusbar)的使用


狀態欄顯示的信息分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);//顯示永久信息

參考:

  1. http://blog.csdn.net/tengweitw/article/details/22511521
  2. http://blog.csdn.net/u010002704/article/details/39060437


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM