[Qt]状态栏QStatusBar使用



原创文章,欢迎转载。转载请注明:转载自 祥的博客

原文链接:https://blog.csdn.net/humanking7/article/details/88065425


文章目录

    • @[toc]
  • 1.效果
  • 2.代码
    • h文件
    • cpp文件
  • 3.扩展

Qt状态栏QStatusBar使用

1.效果

[Qt]状态栏QStatusBar使用_第1张图片

[Qt]状态栏QStatusBar使用_第2张图片

2.代码

h文件

#ifndef MAINSATUSTEST_H
#define MAINSATUSTEST_H

#include 
#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

cpp文件

#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++;
}

3.扩展

Qt添加多个状态栏QStatusBar:https://blog.csdn.net/humanking7/article/details/88082382

效果

QLabel的显示圆形: https://blog.csdn.net/humanking7/article/details/88065087
Qt的Layout边缘空白调整: https://blog.csdn.net/humanking7/article/details/88064393
Qt状态栏QStatusBar使用: https://blog.csdn.net/humanking7/article/details/88065425


赞赏码New

你可能感兴趣的:(Qt,Qt实用Trick)