原创文章,欢迎转载。转载请注明:转载自 祥的博客
原文链接:https://cloud.tencent.com/developer/article/1596465
- @[toc]1.效果2.代码h文件cpp文件3.扩展
Qt状态栏QStatusBar使用
#ifndef MAINSATUSTEST_H
#define MAINSATUSTEST_H
#include <QtWidgets/QMainWindow>
#include "ui_mainsatustest.h"
#include "LedLabel.h"
class MainSatusTest : public QMainWindow
{
Q_OBJECT
public:
MainSatusTest(QWidget *parent = 0);
~MainSatusTest();
private:
Ui::MainSatusTestClass ui;
LedLabel* m_status1;
LedLabel* m_status2;
LedLabel* m_status3;
LedLabel* m_status4;
LedLabel* m_status5;
int m_cnt = 0;
private slots:
void slot_btnColor();
void slot_btnTxt();
};
#endif // MAINSATUSTEST_H
#include "mainsatustest.h"
#pragma execution_character_set("utf-8")
MainSatusTest::MainSatusTest(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
m_status1 = new LedLabel(this, "永久信息");
m_status2 = new LedLabel(this, "灰色");
m_status3 = new LedLabel(this, "灰色");
m_status4 = new LedLabel(this, "灰色");
m_status5 = new LedLabel(this, "灰色");
ui.stBar->addPermanentWidget(m_status1);//永久信息窗口 - 不会被一般消息覆盖
ui.stBar->addWidget(m_status2);//正常信息窗口 - 会被showMessage()的消息覆盖
ui.stBar->addWidget(m_status3);
ui.stBar->addWidget(m_status4);
ui.stBar->addWidget(m_status5);
ui.stBar->setSizeGripEnabled(false);//去掉状态栏右下角的三角
connect(ui.btn_color, SIGNAL(clicked()), this, SLOT(slot_btnColor()));//发送数据
connect(ui.btn_txt, SIGNAL(clicked()), this, SLOT(slot_btnTxt()));//发送数据
}
void MainSatusTest::slot_btnTxt()
{
ui.stBar->showMessage("临时信息...(显示3秒钟)", 3000); // 显示临时信息,时间3秒钟,不会遮盖永久窗口
}
void MainSatusTest::slot_btnColor()
{
if (m_cnt > 3 || m_cnt < 0)
{
m_cnt = 0;
}
QString strShow;
switch (m_cnt)
{
case 0://灰色
strShow = "这是 灰色";
break;
case 1://绿色
strShow = "这是 绿色";
break;
case 2://黄色
strShow = "这是 黄色";
break;
case 3://红色
strShow = "这是 红色";
break;
}
m_status1->updateUI(m_cnt, "永久信息");
m_status2->updateUI(m_cnt, strShow);
m_status3->updateUI(m_cnt, strShow);
m_status4->updateUI(m_cnt, strShow);
m_status5->updateUI(m_cnt, strShow);
m_cnt++;
}
Qt添加多个状态栏QStatusBar:https://cloud.tencent.com/developer/article/1596462
QLabel的显示圆形: https://cloud.tencent.com/developer/article/1596460
Qt的Layout边缘空白调整: https://cloud.tencent.com/developer/article/1596459
Qt状态栏QStatusBar使用: https://cloud.tencent.com/developer/article/1596465