[Qt]状态栏QStatusBar使用
Qt 状态栏 使用
2023-09-14 09:07:12 时间
1.效果
2.代码
h文件
#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
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
原文:https://blog.csdn.net/humanking7/article/details/88065425
相关文章
- 【分享】做了个QT通用图像处理小框架
- QT软件开发-得到唯一文件名-当前时间与GUID
- Linux系统使用Qt开发快速入门教程(linux下qt教程)
- 编程Linux下Qt实例编程:从入门到精通(linux下qt实例)
- Linux串口应用开发实践——Qt篇(linux串口qt)
- 使用Qt快速连接MySQL数据库(qt连接mysql)
- Linux下Qt实现串口通信(linux下qt串口)
- Linux编译Qt:一步一步教程(linux编译qt)
- 数据库使用Qt连接Oracle数据库:一步一步实现(qt连接oracle)
- 轻松上手,Qt在Linux安装教程,让你快速掌握技巧!(qt在linux安装)
- 的整合『使用 Qt 与MySQL实现创新性的数据库应用』(qt与mysql)
- 在Linux上开发应用程序:Qt系列版本深入解析(linux版本qt)
- 集成开发Linux与Qt集成开发:实现无缝交互(linux与qt)
- Linux Qt窗口:快速构建你的GUI界面(linux qt 窗口)
- QT处理SqlServer数据,从入门到精通(QT读SqlServer)
- QT开发MSSQL数据库技术实现(qt mssql)
- Linux下Qt音频播放:轻松享受音乐乐活力(linux下qt音频播放)
- 使用Linux和Qt搭建强大的应用环境(linux qt 环境)
- MySQL和QT不配套使用,无法实现事务处理(mysql不支持qt事务)
- Redis与Qt实现完美连接(redis连接qt)
- Redis使用Qt解决读写互斥问题(redis读写互斥qt)