主窗口的状态栏指针:
//.h
QStatusBar *statusBar() const;//定义
//.cpp
this->statusBar();//调用
信息种类:临时,一般,永久。
1)临时信息:
//显示临时信息
statusBar()->showMessage(tr("系统已初始化完成……"), 6000);//显示临时信息,6s后关闭
2)一般信息:
m_pIP1 = new QLabel(this);
m_pIP1->setFont(ft);
m_pIP1->setStyleSheet("color:red;");
m_pIP1->setText(tr("检测工位客户端待连接……"));
m_pIP2 = new QLabel(this);
m_pIP2->setFont(ft);
m_pIP2->setStyleSheet("color:red;");
m_pIP2->setText(tr("PLC客户端待连接……"));
statusBar()->addWidget(m_pIP1);//获取默认的状态栏,然后添加东西,一般添加一个lable。
statusBar()->addWidget(m_pIP2);//addWidget---添加一般信息
3)永久信息:
QLabel *per1 = new QLabel("系统已就绪 ", this);
QFont ft;
ft.setPointSize(12);
per1->setFont(ft);
QPalette pe;
pe.setColor(QPalette::WindowText, Qt::white);
per1->setPalette(pe);
statusBar()->addPermanentWidget(per1);//addPermanentWidget--该函数用于添加永久信息,在最右侧显示。