Qt 状态栏(statusbar)的使用


状态栏显示的信息分3种 
1. 一般信息,用QLabel 代表 
2. 永久信息,文本会一直显示在状态栏的最右边。 
3. 临时信息,指定信息现实的时间。时间到即信息消失。

 1 QLabel *locationLabel;  2 locationLabel = new QLabel("July");  3 locationLabel->setAlignment(Qt::AlignCenter);  4 locationLabel->setMinimumSize(locationLabel->sizeHint());  5 
 6 QLabel *aixLabel;  7 aixLabel = new QLabel("\"CTRL + H\" for help");  8 
 9 //Optional
10 statusBar()->setStyleSheet(QString("QStatusBar::item{border: 0px}")); // 设置不显示label的边框
11 statusBar()->setSizeGripEnabled(false); //设置是否显示右边的大小控制点
12 statusBar()->addWidget(locationLabel); 13 statusBar()->addWidget(aixLabel, 1); 14 
15 QLabel *per1 = new QLabel("Ready1", this); 16 QLabel *per2 = new QLabel("Ready2", this); 17 QLabel *per3 = new QLabel("Ready3", this); 18 statusBar()->addPermanentWidget(per1); //现实永久信息
19 statusBar()->addPermanentWidget(per2); 20 statusBar()->insertPermanentWidget(2, per3); 21 
22 statusBar()->showMessage("Status is here...", 3000); // 显示临时信息,时间3秒钟.
 1 MainWindow::MainWindow(QWidget *parent) :  2  QMainWindow(parent),  3     ui(new Ui::MainWindow)  4 {  5     ui->setupUi(this);  6 
 7 // QLabel *normal=new QLabel("正常信息",this);  8 // ui->statusBar->addWidget(normal);//显示正常信息
 9 
10     ui->statusBar->setSizeGripEnabled(false);//去掉状态栏右下角的三角
11 
12     ui->statusBar->showMessage(tr("临时信息!"),2000);//显示临时信息2000ms 前面的正常信息被覆盖 当去掉后一项时,会一直显示
13 
14     QLabel *permanent=new QLabel(this); 15     permanent->setFrameStyle(QFrame::Box|QFrame::Sunken); 16     permanent->setText(tr("<a href=\"http://tengweitw.ueuo.com\">永久信息</a>")); 17     permanent->setOpenExternalLinks(true);//设置可以打开网站链接
18     ui->statusBar->addPermanentWidget(permanent);//显示永久信息
19 }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM