上图为最终实现的效果。下方会显示历史记录,超过阈值将会标红;右方将显示实时告警记录,三个部位均实时进行变化。且图中柱状图可点击进入详情页面,同时也是实时更新。
下面为实现代码:
realtime_detect.h
#ifndef REALTIME_DETECT_H
#define REALTIME_DETECT_H
#include <QWidget>
#include <QQueue>
#include <QDebug>
#include <QTime>
#include <QTimer>
#include <QPushButton>
#include <QRandomGenerator>
#include "autoresize.h"
#define X_800CDMA 60
#define X_900GSM 160
#define X_1800DCS 260
#define X_2100WCDMA 360
#define X_B41LTE 460
#define X_2GWIFI 560
namespace Ui {
class Realtime_Detect;
}
class Realtime_Detect : public QWidget
{
Q_OBJECT
public:
explicit Realtime_Detect(QWidget *parent = nullptr);
~Realtime_Detect();
void Build_column(int pos_x,int value);
void input_all_value(int x_7005G,int x_800CDMA,int x_900GSM,int x_1800DCS,int x_2100WCDMA,int x_B5LTE,int x_B8LTE,int x_B1LTE,int x_B3LTE,int x_B34LTE,int x_B38LTE,int x_B39LTE,int x_B40LTE,int x_B41LTE,int x_N415G,int x_N785G,int x_2GWIFI,int x_5GWIFI);
QQueue<QString> show_Text;//右边文字显示队列
//下方历史记录队列
QQueue<int> his_800_CDMA;
QQueue<int> his_900_GSM;
QQueue<int> his_1800_DCS;
QQueue<int> his_2100_WCDMA;
QQueue<int> his_B41_LTE;
QQueue<int> his_2GWIFI;
private:
Ui::Realtime_Detect *ui;
AutoResize *m_autoResizeHandler;
// 历史记录队列
void create_history_Queue();
void init_show_history_Queue();
void Refresh_history();
// 右侧文字显示队列
void init_show_Text_Queue();
void Refresh_text();
// 初始化柱状图x坐标
void init_x_text();
void sleep(int msec);
protected:
//界面比列事件
void resizeEvent(QResizeEvent * event);
int test_count=0;
private slots:
void on_test_btn_clicked();
};
#endif // REALTIME_DETECT_H
realtime_detect.cpp
#include "realtime_detect.h"
#include "ui_realtime_detect.h"
extern double global_height,global_width;
Realtime_Detect::Realtime_Detect(QWidget *parent) :
QWidget(parent),
ui(new Ui::Realtime_Detect)
{
ui->setupUi(this);
/** 添加自适应部分 **/
m_autoResizeHandler=new AutoResize(this,this->rect().width(),this->rect().height());
//先与要自适应的枚举量控件进行或运算算出值
m_autoResizeHandler->setAutoResizeFlag(
AutoResize::INCLUDE_BUTTON|AutoResize::INCLUDE_COMBOBOX|
AutoResize::INCLUDE_EDITOR|AutoResize::INCLUDE_LABEL
);
m_autoResizeHandler->pushAllResizeItem();
init_show_Text_Queue();//将文字队列置空
init_x_text();//初始化柱状图横坐标,使其能够自动换行。
create_history_Queue();
init_show_history_Queue();
}
Realtime_Detect::~Realtime_Detect()
{
delete ui;
}
void Realtime_Detect::Build_column(int pos_x, int value)
{
/** 1.定义柱状图的圆柱宽度,以及根据pos定义相关名称信息 **/
int column_width = 15;
double ratex=global_width/1024.0;
double ratey=global_height/600.0;
QString showText_tip="";//初始化右侧告警文字
QString this_col="";//初始化选中信道文字
QQueue<int> *this_queue =new QQueue<int>;//初始化指向队列指针
//定义相关名称信息
switch (pos_x) {
case X_800CDMA:
showText_tip=" 800检测到可疑目标(强度";
this_col="800 CDMA";
this_queue=&his_800_CDMA;
break;
case X_900GSM:
showText_tip=" 900检测到可疑目标(强度";
this_col="900 GSM";
this_queue=&his_900_GSM;
break;
case X_1800DCS:
showText_tip=" 1800检测到可疑目标(强度";
this_col="1800 DCS";
this_queue=&his_1800_DCS;
break;
case X_2100WCDMA:
showText_tip=" 2100检测到可疑目标(强度";
this_col="2100 WCDMA";
this_queue=&his_2100_WCDMA;
break;
case X_B41LTE:
showText_tip=" B41检测到可疑目标(强度";
this_col="B41 LTE";
this_queue=&his_B41_LTE;
break;
case X_2GWIFI:
showText_tip=" 2.4G检测到可疑目标(强度";
this_col="2.4G WIFI";
this_queue=&his_2GWIFI;
break;
}
/** 2.根据传入坐标和值,绘制圆柱 **/
QString objectName = QString("column_%1").arg(pos_x);
QPushButton *column = findChild<QPushButton *>(objectName);
if (column) {//当已存在时,直接改变圆柱大小
column->setGeometry(pos_x*ratex,(470-value*4)*ratey,column_width*ratex,value*4*ratey);
}else {//不存在时,重新创建对象
column =new QPushButton(this);
column->setObjectName(objectName);
/** 6.在信号内为每个圆柱创建点击响应事件,弹出新窗口显示每秒的值 **/
connect(column,&QPushButton::clicked,this,[=](){
int pre_width=865;
int pre_height=600;
/** 6.1 规范地创建背景 **/
QWidget *w=new QWidget(this);
w->setObjectName("widget_bk");
w->setGeometry(100,100,pre_width*ratex,pre_height*ratey);
w->setStyleSheet("#widget_bk{background-image: url(:/new/IMG/toushi.png);}");
w->show();
/** 6.2.1 创建标题 **/
QLabel *text=new QLabel(w);
text->setStyleSheet("background-color: rgb(10, 112, 190);color: rgb(255, 255, 255);font-family:SimHei;font-size:16pt;font-weight:bold;");
text->setGeometry(0,0,pre_width*ratex,40*ratey);
text->setText(" 单 独 定 位");
text->show();
/** 6.2.2 创建标签 **/
QLabel *tips=new QLabel(w);
tips->setStyleSheet("color: rgb(255, 255, 255);font-family:simhei;font-size:11pt;");
tips->setGeometry(640*ratex,70*ratey,220*ratex,25*ratey);
tips->setText("当 前 目 标:");
tips->show();
/** 6.2.3 创建检测信道标签 以及两侧图标 **/
QLabel *channel_tips=new QLabel(w);
channel_tips->setStyleSheet("color: rgb(255, 255, 255);font-family:simhei;font-size:11pt;");
channel_tips->setGeometry(670*ratex,100*ratey,100*ratex,30*ratey);
channel_tips->setAlignment(Qt::AlignCenter);
channel_tips->setText(this_col);
channel_tips->show();
QLabel *ico_left=new QLabel(w);
ico_left->setGeometry(640*ratex,100*ratey,30*ratex,30*ratey);
ico_left->setStyleSheet("color:white;border-radius:15px;image: url(:/new/IMG/leftico.png);");
ico_left->show();
QLabel *ico_right=new QLabel(w);
ico_right->setGeometry(770*ratex,100*ratey,30*ratex,30*ratey);
ico_right->setStyleSheet("color:white;border-radius:15px;image: url(:/new/IMG/rightico.png);");
ico_right->show();
/** 6.2.4 创建接收到Value的显示框 以及背景 **/
QLabel *value_label=new QLabel(w);
value_label->setGeometry(670*ratex,160*ratey,100*ratex,100*ratey);
value_label->setAlignment(Qt::AlignCenter);
value_label->setText(QString::number(this_queue->value(29)));
value_label->setStyleSheet("font-size:18pt;font-family:simhei;color:white;border-radius:15px;image: url(:/new/IMG/value_label.png);");
value_label->show();
/** 6.2.5 创建左侧坐标系,要与前面坐标系样式相同 **/
QLabel *X_roller=new QLabel(w);
X_roller->setGeometry(20*ratex,470*ratey,600*ratex,2*ratey);
X_roller->setStyleSheet("background-color:black;");
X_roller->show();
QLabel *X_2=new QLabel(w);
X_2->setGeometry(20*ratex,70*ratey,600*ratex,2*ratey);
X_2->setStyleSheet("background-color: rgb(85, 255, 255);");
X_2->show();
QLabel *X_3=new QLabel(w);
X_3->setGeometry(20*ratex,150*ratey,600*ratex,2*ratey);
X_3->setStyleSheet("background-color: rgb(85, 255, 255);");
X_3->show();
QLabel *X_4=new QLabel(w);
X_4->setGeometry(20*ratex,230*ratey,600*ratex,2*ratey);
X_4->setStyleSheet("background-color: rgb(85, 255, 255);");
X_4->show();
QLabel *X_5=new QLabel(w);
X_5->setGeometry(20*ratex,310*ratey,600*ratex,2*ratey);
X_5->setStyleSheet("background-color: rgb(85, 255, 255);");
X_5->show();
QLabel *X_6=new QLabel(w);
X_6->setGeometry(20*ratex,390*ratey,600*ratex,2*ratey);
X_6->setStyleSheet("background-color: rgb(85, 255, 255);");
X_6->show();
QLabel *X_7=new QLabel(w);
X_7->setGeometry(20*ratex,110*ratey,600*ratex,2*ratey);
X_7->setStyleSheet("background-color: rgb(39, 198, 255);");
X_7->show();
QLabel *X_8=new QLabel(w);
X_8->setGeometry(20*ratex,190*ratey,600*ratex,2*ratey);
X_8->setStyleSheet("background-color: rgb(39, 198, 255);");
X_8->show();
QLabel *X_9=new QLabel(w);
X_9->setGeometry(20*ratex,270*ratey,600*ratex,2*ratey);
X_9->setStyleSheet("background-color: rgb(39, 198, 255);");
X_9->show();
QLabel *X_10=new QLabel(w);
X_10->setGeometry(20*ratex,350*ratey,600*ratex,2*ratey);
X_10->setStyleSheet("background-color: rgb(39, 198, 255);");
X_10->show();
QLabel *X_11=new QLabel(w);
X_11->setGeometry(20*ratex,430*ratey,600*ratex,2*ratey);
X_11->setStyleSheet("background-color: rgb(39, 198, 255);");
X_11->show();
QLabel *Y_roller=new QLabel(w);
Y_roller->setGeometry(20*ratex,60*ratey,2*ratex,411*ratey);
Y_roller->setStyleSheet("background-color:black;");
Y_roller->show();
/** 6.2.6 进入界面时读取队列并创建圆柱,之后每秒执行一次读取队列,将队列值展示出来 **/
for(int i=12;i<30;i++){//创建圆柱
//1.设置圆柱名称
QString colname = QString("child_col_%1").arg(i);
QLabel *child_col =new QLabel(w);
child_col->setObjectName(colname);
//2.设置圆柱位置和样式
child_col->setGeometry((30+(i-12)*30)*ratex,(470-this_queue->value(i)*4)*ratey,column_width*ratex,this_queue->value(i)*4*ratey);
child_col->setStyleSheet("background-color:rgb(221,30,0);color:white;font-size:11pt;font-family:simhei;");
//3.显示圆柱的值
child_col->setText(QString::number(this_queue->value(i)));
child_col->setAlignment(Qt::AlignCenter);
child_col->show();
}
//4.之后每秒执行一次,更新界面中的圆柱
QTimer *countTime = new QTimer(w);
connect(countTime,&QTimer::timeout,this,[=](){
value_label->setText(QString::number(this_queue->value(29)));
for(int i=12;i<30;i++){
QString colname = QString("child_col_%1").arg(i);
QLabel *child_col = findChild<QLabel *>(colname);
if (child_col) {//当已存在时,直接改变圆柱大小
child_col->setGeometry((30+(i-12)*30)*ratex,(470-this_queue->value(i)*4)*ratey,column_width*ratex,this_queue->value(i)*4*ratey);
child_col->setText(QString::number(this_queue->value(i)));
}
}
});
countTime->start(1000);
/** 6.3 创建返回按钮,绑定关闭信号 **/
QPushButton *close_btn = new QPushButton(w);
close_btn->setGeometry(550*ratex,10*ratey,75*ratex,23*ratey);
close_btn->setStyleSheet("QPushButton {background-color:white;border-style:outset; border-color: black; border-top-width:1px;border-left-width:1px;border-bottom-width:2px;border-right-width:2px;font: bold 13pt simhei; }QPushButton:hover{background-color:rgb(240, 240, 240);} QPushButton:pressed{background-color:rgb(240, 240, 240); padding-left:3px;padding-top:3px;}");
close_btn->setText("返 回");
close_btn->show();
connect(close_btn,&QPushButton::clicked,w,[=](){
w->deleteLater();
disconnect(countTime);
});
});
column->setGeometry(pos_x*ratex,(470-value*4)*ratey,column_width*ratex,value*4*ratey);
}
/** 3.根据值变换圆柱颜色 **/
if(value<10){
column->setStyleSheet("background-color:rgb(168,221,0);");
}else if(value>=10&&value<15){
column->setStyleSheet("background-color:rgb(188,221,0);");
}else if(value>=15&&value<20){
column->setStyleSheet("background-color:rgb(204,221,0);");
}else if(value>=20&&value<25){
column->setStyleSheet("background-color:rgb(221,210,0);");
}else if(value>=25&&value<30){
column->setStyleSheet("background-color:rgb(221,193,0);");
}else if(value>=30&&value<35){
column->setStyleSheet("background-color:rgb(221,171,0);");
}else if(value>=35&&value<40){
column->setStyleSheet("background-color:rgb(221,160,0);");
}else if(value>=40&&value<45){
column->setStyleSheet("background-color:rgb(221,143,0);");
}else if(value>=45&&value<50){
column->setStyleSheet("background-color:rgb(221,128,0);");
}else if(value>=50&&value<55){
column->setStyleSheet("background-color:rgb(221,105,0);");
}else if(value>=55&&value<60){
column->setStyleSheet("background-color:rgb(221,83,0);");
}else if(value>=60&&value<70){
column->setStyleSheet("background-color:rgb(221,66,0);");
}else if(value>=70&&value<80){
column->setStyleSheet("background-color:rgb(221,48,0);");
}else if(value>=80&&value<=100){
column->setStyleSheet("background-color:rgb(221,30,0);");
}
column->show();
/** 4.为圆柱上方添加值 **/
QString valueName = QString("colvalue_%1").arg(pos_x);
QLabel *col_value = findChild<QLabel *>(valueName);
if (col_value) {//当已存在时,直接改变位置
col_value->setGeometry((pos_x-1)*ratex,(470-value*4-12)*ratey,(column_width+2)*ratex,10*ratey);
}else {//不存在时,重新创建对象
col_value =new QLabel(this);
col_value->setObjectName(valueName);
col_value->setGeometry((pos_x-1)*ratex,(470-value*4-12)*ratey,(column_width+2)*ratex,10*ratey);
}
col_value->setStyleSheet("color:black;font-family:Simhei;");
col_value->setAlignment(Qt::AlignCenter);
col_value->setText(QString::number(value));
col_value->show();
/** 5.判断当信号超过阈值时,对左侧栏和历史记录队列进行插入 **/
if(value>=60){
QDateTime currentTime = QDateTime::currentDateTime();
QString timeString = currentTime.toString("hh:mm:ss");//获取时间
//对右边的文字:先出队列,再让新的入队列
show_Text.dequeue();
show_Text.enqueue(timeString+showText_tip+QString::number(value)+")");
this_queue->dequeue();
this_queue->enqueue(value);
Refresh_text();
}else{
this_queue->dequeue();
this_queue->enqueue(value);
}
QString checkname=("widget_bk");
QWidget *checkw=findChild<QWidget*>(checkname);
if(!checkw){//当打开详情时不刷新历史记录,从而避免了阻塞
Refresh_history();
}
}
void Realtime_Detect::input_all_value(int v_7005G, int v_800CDMA, int v_900GSM, int v_1800DCS, int v_2100WCDMA, int v_B5LTE, int v_B8LTE, int v_B1LTE, int v_B3LTE, int v_B34LTE, int v_B38LTE, int v_B39LTE, int v_B40LTE, int v_B41LTE, int v_N415G, int v_N785G, int v_2GWIFI, int v_5GWIFI)
{
Build_column(X_800CDMA,v_800CDMA);
Build_column(X_900GSM,v_900GSM);
Build_column(X_1800DCS,v_1800DCS);
Build_column(X_2100WCDMA,v_2100WCDMA);
Build_column(X_B41LTE,v_B41LTE);//14
Build_column(X_2GWIFI,v_2GWIFI);
}
void Realtime_Detect::create_history_Queue()
{
for (int i=0;i<30;i++) {
/** 800 CMDA **/
/** 依次创建并命名 **/
QLabel *label_800 = new QLabel(this); // 创建 QLabel 对象
QString objectName2 = QString("his_800_%1").arg(i);
label_800->setObjectName(objectName2); // 设置对象名称
/** 设置位置和颜色 **/
label_800->setGeometry(60,560-i*2,15,2);
label_800->setStyleSheet("background-color: rgb(4, 137, 208);");
/** 900 GSM **/
/** 依次创建并命名 **/
QLabel *label_900 = new QLabel(this); // 创建 QLabel 对象
QString objectName3 = QString("his_900_%1").arg(i);
label_900->setObjectName(objectName3); // 设置对象名称
/** 设置位置和颜色 **/
label_900->setGeometry(160,560-i*2,15,2);
label_900->setStyleSheet("background-color: rgb(4, 137, 208);");
/** 1800 DCS **/
/** 依次创建并命名 **/
QLabel *label_1800 = new QLabel(this); // 创建 QLabel 对象
QString objectName4 = QString("his_1800_%1").arg(i);
label_1800->setObjectName(objectName4); // 设置对象名称
/** 设置位置和颜色 **/
label_1800->setGeometry(260,560-i*2,15,2);
label_1800->setStyleSheet("background-color: rgb(4, 137, 208);");
/** 2100 WCDMA **/
/** 依次创建并命名 **/
QLabel *label_2100 = new QLabel(this); // 创建 QLabel 对象
QString objectName5 = QString("his_2100_%1").arg(i);
label_2100->setObjectName(objectName5); // 设置对象名称
/** 设置位置和颜色 **/
label_2100->setGeometry(360,560-i*2,15,2);
label_2100->setStyleSheet("background-color: rgb(4, 137, 208);");
/** B41 LTE**/
/** 依次创建并命名 **/
QLabel *label_B41 = new QLabel(this); // 创建 QLabel 对象
QString objectName14 = QString("his_B41_%1").arg(i);
label_B41->setObjectName(objectName14); // 设置对象名称
/** 设置位置和颜色 **/
label_B41->setGeometry(460,560-i*2,15,2);
label_B41->setStyleSheet("background-color: rgb(4, 137, 208);");
/** 2.4G WIFI**/
/** 依次创建并命名 **/
QLabel *label_2G = new QLabel(this); // 创建 QLabel 对象
QString objectName17 = QString("his_2GWIFI_%1").arg(i);
label_2G->setObjectName(objectName17); // 设置对象名称
/** 设置位置和颜色 **/
label_2G->setGeometry(560,560-i*2,15,2);
label_2G->setStyleSheet("background-color: rgb(4, 137, 208);");
}
}
void Realtime_Detect::init_show_history_Queue()
{
for(int i=0;i<30;i++){
his_800_CDMA.enqueue(0);
his_900_GSM.enqueue(0);
his_1800_DCS.enqueue(0);
his_2100_WCDMA.enqueue(0);
his_B41_LTE.enqueue(0);
his_2GWIFI.enqueue(0);
}
}
void Realtime_Detect::Refresh_history()
{
for(int i=0;i<30;i++){
// 获取对应的 QLabel 对象
QString name_800 = "his_800_" + QString::number(i);
QLabel *label_800 = findChild<QLabel *>(name_800);
if(his_800_CDMA.value(i)>=60){
label_800->setStyleSheet("background-color:red;");
}else {
label_800->setStyleSheet("background-color: rgb(4, 137, 208);");
}
// 获取对应的 QLabel 对象
QString name_900 = "his_900_" + QString::number(i);
QLabel *label_900 = findChild<QLabel *>(name_900);
if(his_900_GSM.value(i)>=60){
label_900->setStyleSheet("background-color:red;");
}else {
label_900->setStyleSheet("background-color: rgb(4, 137, 208);");
}
// 获取对应的 QLabel 对象
QString name_1800 = "his_1800_" + QString::number(i);
QLabel *label_1800 = findChild<QLabel *>(name_1800);
if(his_1800_DCS.value(i)>=60){
label_1800->setStyleSheet("background-color:red;");
}else {
label_1800->setStyleSheet("background-color: rgb(4, 137, 208);");
}
// 获取对应的 QLabel 对象
QString name_2100 = "his_2100_" + QString::number(i);
QLabel *label_2100 = findChild<QLabel *>(name_2100);
if(his_2100_WCDMA.value(i)>=60){
label_2100->setStyleSheet("background-color:red;");
}else {
label_2100->setStyleSheet("background-color: rgb(4, 137, 208);");
}
// 获取对应的 QLabel 对象
QString name_b41 = "his_B41_" + QString::number(i);
QLabel *label_b41 = findChild<QLabel *>(name_b41);
if(his_B41_LTE.value(i)>=60){
label_b41->setStyleSheet("background-color:red;");
}else {
label_b41->setStyleSheet("background-color: rgb(4, 137, 208);");
}
// 获取对应的 QLabel 对象
QString name_2Gwifi = "his_2GWIFI_" + QString::number(i);
QLabel *label_2Gwifi = findChild<QLabel *>(name_2Gwifi);
if(his_2GWIFI.value(i)>=60){
label_2Gwifi->setStyleSheet("background-color:red;");
}else {
label_2Gwifi->setStyleSheet("background-color: rgb(4, 137, 208);");
}
}
}
// 将队列置空
void Realtime_Detect::init_show_Text_Queue()
{
for(int i=0;i<20;i++){
show_Text.enqueue("");
}
}
void Realtime_Detect::Refresh_text()
{
for(int i=0;i<20;i++){
// 获取对应的 QLabel 对象
QString labelName = "Text_Q" + QString::number(i);
QLabel *label = findChild<QLabel *>(labelName);
label->setText(show_Text.value(i)); // 设置 QLabel 的文本
}
}
void Realtime_Detect::init_x_text()
{
ui->x_800CDMA->setWordWrap(true);
ui->x_900GSM->setWordWrap(true);
ui->x_1800DCS->setWordWrap(true);
ui->x_2100WCDMA->setWordWrap(true);
ui->x_B41LTE->setWordWrap(true);
ui->x_2GWIFI->setWordWrap(true);
}
void Realtime_Detect::sleep(int msec)
{
QTime reachtime = QTime::currentTime().addMSecs(msec);
while(QTime::currentTime()<reachtime){
QCoreApplication::processEvents(QEventLoop::AllEvents,100);
}
}
void Realtime_Detect::resizeEvent(QResizeEvent *event)
{
m_autoResizeHandler->doAutoResize();
ui->bkground->resize(this->width(),this->height());
}
void Realtime_Detect::on_test_btn_clicked()
{
int randomNumber1 = QRandomGenerator::global()->bounded(1, 100); // 生成 1 到 100 之间的随机整数
int randomNumber2 = QRandomGenerator::global()->bounded(1, 100); // 生成 1 到 100 之间的随机整数
int randomNumber3 = QRandomGenerator::global()->bounded(1, 100); // 生成 1 到 100 之间的随机整数
int randomNumber4= QRandomGenerator::global()->bounded(1, 100); // 生成 1 到 100 之间的随机整数
int randomNumber5 = QRandomGenerator::global()->bounded(1, 100); // 生成 1 到 100 之间的随机整数
int randomNumber6 = QRandomGenerator::global()->bounded(1, 100); // 生成 1 到 100 之间的随机整数
int randomNumber7 = QRandomGenerator::global()->bounded(1, 100); // 生成 1 到 100 之间的随机整数
int randomNumber8 = QRandomGenerator::global()->bounded(1, 100); // 生成 1 到 100 之间的随机整数
int randomNumber9 = QRandomGenerator::global()->bounded(1, 100); // 生成 1 到 100 之间的随机整数
int randomNumber10 = QRandomGenerator::global()->bounded(1, 100); // 生成 1 到 100 之间的随机整数
int randomNumber11 = QRandomGenerator::global()->bounded(1, 100); // 生成 1 到 100 之间的随机整数
int randomNumber12 = QRandomGenerator::global()->bounded(1, 100); // 生成 1 到 100 之间的随机整数
int randomNumber13 = QRandomGenerator::global()->bounded(1, 100); // 生成 1 到 100 之间的随机整数
int randomNumber14 = QRandomGenerator::global()->bounded(1, 100); // 生成 1 到 100 之间的随机整数
int randomNumber15 = QRandomGenerator::global()->bounded(1, 100); // 生成 1 到 100 之间的随机整数
int randomNumber16 = QRandomGenerator::global()->bounded(1, 100); // 生成 1 到 100 之间的随机整数
int randomNumber17 = QRandomGenerator::global()->bounded(1, 100); // 生成 1 到 100 之间的随机整数
int randomNumber18 = QRandomGenerator::global()->bounded(1, 100); // 生成 1 到 100 之间的随机整数
input_all_value(randomNumber1,randomNumber2,randomNumber3,randomNumber4,randomNumber5,randomNumber6,randomNumber7,randomNumber8,randomNumber9,randomNumber10,randomNumber11,randomNumber12,randomNumber13,randomNumber14,randomNumber15,randomNumber16,randomNumber17,randomNumber18);
}
可以看到由于技术问题阉割了一部分,原本是显示18路信息的,后改成了6路信息并放到了这里。
UI界面的代码如下
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Realtime_Detect</class>
<widget class="QWidget" name="Realtime_Detect">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>865</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QWidget" name="bkground" native="true">
<property name="geometry">
<rect>
<x>0</x>
<y>20</y>
<width>1024</width>
<height>600</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-image: url(:/new/IMG/toushi.png);</string>
</property>
</widget>
<widget class="QLabel" name="labelTableText">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>865</width>
<height>40</height>
</rect>
</property>
<property name="font">
<font>
<family>SimHei</family>
<pointsize>16</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(10, 112, 190);
color: rgb(255, 255, 255);
font-family:SimHei;
font-size:16pt;
font-weight:bold;</string>
</property>
<property name="text">
<string> 实 时 信 号</string>
</property>
</widget>
<widget class="QLabel" name="label_line2">
<property name="geometry">
<rect>
<x>0</x>
<y>40</y>
<width>865</width>
<height>2</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(164, 200, 155);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="X_roller">
<property name="geometry">
<rect>
<x>20</x>
<y>470</y>
<width>600</width>
<height>2</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(0, 0, 0);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="Y_roller">
<property name="geometry">
<rect>
<x>20</x>
<y>60</y>
<width>2</width>
<height>410</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(0, 0, 0);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="scale">
<property name="geometry">
<rect>
<x>5</x>
<y>500</y>
<width>2</width>
<height>60</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(0, 0, 0);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="scale_zero">
<property name="geometry">
<rect>
<x>5</x>
<y>500</y>
<width>10</width>
<height>2</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(0, 0, 0);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="scale_half_min">
<property name="geometry">
<rect>
<x>5</x>
<y>530</y>
<width>10</width>
<height>2</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(0, 0, 0);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="scale_min">
<property name="geometry">
<rect>
<x>5</x>
<y>559</y>
<width>10</width>
<height>2</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(0, 0, 0);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="x_800CDMA">
<property name="geometry">
<rect>
<x>60</x>
<y>475</y>
<width>21</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<family>simhei</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">font-family:simhei;font-size:9pt;</string>
</property>
<property name="text">
<string>800 CDMA</string>
</property>
</widget>
<widget class="QLabel" name="x_900GSM">
<property name="geometry">
<rect>
<x>160</x>
<y>475</y>
<width>21</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<family>simhei</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">font-family:simhei;font-size:9pt;</string>
</property>
<property name="text">
<string>900 GSM</string>
</property>
</widget>
<widget class="QLabel" name="x_1800DCS">
<property name="geometry">
<rect>
<x>260</x>
<y>475</y>
<width>21</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<family>simhei</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">font-family:simhei;font-size:9pt;</string>
</property>
<property name="text">
<string>1800 DCS</string>
</property>
</widget>
<widget class="QLabel" name="x_2100WCDMA">
<property name="geometry">
<rect>
<x>360</x>
<y>475</y>
<width>26</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<family>simhei</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">font-family:simhei;font-size:9pt;</string>
</property>
<property name="text">
<string>2100 WCDMA</string>
</property>
</widget>
<widget class="QLabel" name="x_B41LTE">
<property name="geometry">
<rect>
<x>460</x>
<y>475</y>
<width>21</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<family>simhei</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">font-family:simhei;font-size:9pt;</string>
</property>
<property name="text">
<string>B41 LTE</string>
</property>
</widget>
<widget class="QLabel" name="x_2GWIFI">
<property name="geometry">
<rect>
<x>560</x>
<y>475</y>
<width>21</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<family>simhei</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">font-family:simhei;font-size:9pt;</string>
</property>
<property name="text">
<string>2.4G WIFI</string>
</property>
</widget>
<widget class="QLabel" name="X_roller_2">
<property name="geometry">
<rect>
<x>20</x>
<y>70</y>
<width>600</width>
<height>2</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(85, 255, 255);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="X_roller_3">
<property name="geometry">
<rect>
<x>20</x>
<y>150</y>
<width>600</width>
<height>2</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(85, 255, 255);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="X_roller_4">
<property name="geometry">
<rect>
<x>20</x>
<y>230</y>
<width>600</width>
<height>2</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(85, 255, 255);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="X_roller_5">
<property name="geometry">
<rect>
<x>20</x>
<y>310</y>
<width>600</width>
<height>2</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(85, 255, 255);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="X_roller_6">
<property name="geometry">
<rect>
<x>20</x>
<y>390</y>
<width>600</width>
<height>2</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(85, 255, 255);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="X_roller_7">
<property name="geometry">
<rect>
<x>20</x>
<y>110</y>
<width>600</width>
<height>2</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(39, 198, 255);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="X_roller_8">
<property name="geometry">
<rect>
<x>20</x>
<y>190</y>
<width>600</width>
<height>2</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(39, 198, 255);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="X_roller_9">
<property name="geometry">
<rect>
<x>20</x>
<y>270</y>
<width>600</width>
<height>2</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(39, 198, 255);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="X_roller_10">
<property name="geometry">
<rect>
<x>20</x>
<y>350</y>
<width>600</width>
<height>2</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(39, 198, 255);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="X_roller_11">
<property name="geometry">
<rect>
<x>20</x>
<y>430</y>
<width>600</width>
<height>2</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(39, 198, 255);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="scale_02">
<property name="geometry">
<rect>
<x>8</x>
<y>560</y>
<width>15</width>
<height>15</height>
</rect>
</property>
<property name="font">
<font>
<family>simhei</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">font-family:simhei;font-size:9pt;</string>
</property>
<property name="text">
<string>60s</string>
</property>
</widget>
<widget class="QLabel" name="scale_04">
<property name="geometry">
<rect>
<x>8</x>
<y>485</y>
<width>15</width>
<height>15</height>
</rect>
</property>
<property name="font">
<font>
<family>simhei</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">font-family:simhei;font-size:9pt;</string>
</property>
<property name="text">
<string>0s</string>
</property>
</widget>
<widget class="QLabel" name="Text_Q19">
<property name="geometry">
<rect>
<x>640</x>
<y>70</y>
<width>220</width>
<height>25</height>
</rect>
</property>
<property name="font">
<font>
<family>simhei</family>
<pointsize>11</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">font-size:11pt;color: rgb(255, 255, 255);font-family:simhei;font-size:11pt;</string>
</property>
<property name="text">
<string>13:20:00 2.4G检测到可疑目标(信号55)</string>
</property>
</widget>
<widget class="QLabel" name="Text_Q18">
<property name="geometry">
<rect>
<x>640</x>
<y>95</y>
<width>220</width>
<height>25</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font-size:11pt;color: rgb(255, 255, 255);font-family:simhei;</string>
</property>
<property name="text">
<string>13:20:00 2.4G检测到可疑目标(信号88)</string>
</property>
</widget>
<widget class="QLabel" name="Text_Q17">
<property name="geometry">
<rect>
<x>640</x>
<y>120</y>
<width>220</width>
<height>25</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font-size:11pt;color: rgb(255, 255, 255);font-family:simhei;</string>
</property>
<property name="text">
<string>13:20:00 2.4G检测到可疑目标(信号55)</string>
</property>
</widget>
<widget class="QLabel" name="Text_Q16">
<property name="geometry">
<rect>
<x>640</x>
<y>145</y>
<width>220</width>
<height>25</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font-size:11pt;color: rgb(255, 255, 255);font-family:simhei;</string>
</property>
<property name="text">
<string>13:20:00 2.4G检测到可疑目标(信号55)</string>
</property>
</widget>
<widget class="QLabel" name="Text_Q15">
<property name="geometry">
<rect>
<x>640</x>
<y>170</y>
<width>220</width>
<height>25</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font-size:11pt;color: rgb(255, 255, 255);font-family:simhei;</string>
</property>
<property name="text">
<string>13:20:00 2.4G检测到可疑目标(信号55)</string>
</property>
</widget>
<widget class="QLabel" name="Text_Q14">
<property name="geometry">
<rect>
<x>640</x>
<y>195</y>
<width>220</width>
<height>25</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font-size:11pt;color: rgb(255, 255, 255);font-family:simhei;</string>
</property>
<property name="text">
<string>13:20:00 2.4G检测到可疑目标(信号55)</string>
</property>
</widget>
<widget class="QLabel" name="Text_Q13">
<property name="geometry">
<rect>
<x>640</x>
<y>220</y>
<width>220</width>
<height>25</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);font-family:simhei;font-size:11pt;</string>
</property>
<property name="text">
<string>13:20:00 2.4G检测到可疑目标(信号55)</string>
</property>
</widget>
<widget class="QLabel" name="Text_Q12">
<property name="geometry">
<rect>
<x>640</x>
<y>245</y>
<width>220</width>
<height>25</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);font-family:simhei;font-size:11pt;</string>
</property>
<property name="text">
<string>13:20:00 2.4G检测到可疑目标(信号55)</string>
</property>
</widget>
<widget class="QLabel" name="Text_Q11">
<property name="geometry">
<rect>
<x>640</x>
<y>270</y>
<width>220</width>
<height>25</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);font-family:simhei;font-size:11pt;</string>
</property>
<property name="text">
<string>13:20:00 2.4G检测到可疑目标(信号55)</string>
</property>
</widget>
<widget class="QLabel" name="Text_Q10">
<property name="geometry">
<rect>
<x>640</x>
<y>295</y>
<width>220</width>
<height>25</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);font-family:simhei;font-size:11pt;</string>
</property>
<property name="text">
<string>13:20:00 2.4G检测到可疑目标(信号55)</string>
</property>
</widget>
<widget class="QLabel" name="Text_Q9">
<property name="geometry">
<rect>
<x>640</x>
<y>320</y>
<width>220</width>
<height>25</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font-size:11pt;color: rgb(255, 255, 255);font-family:simhei;</string>
</property>
<property name="text">
<string>13:20:00 2.4G检测到可疑目标(信号55)</string>
</property>
</widget>
<widget class="QLabel" name="Text_Q8">
<property name="geometry">
<rect>
<x>640</x>
<y>345</y>
<width>220</width>
<height>25</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font-size:11pt;color: rgb(255, 255, 255);font-family:simhei;</string>
</property>
<property name="text">
<string>13:20:00 2.4G检测到可疑目标(信号55)</string>
</property>
</widget>
<widget class="QLabel" name="Text_Q7">
<property name="geometry">
<rect>
<x>640</x>
<y>370</y>
<width>220</width>
<height>25</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font-size:11pt;color: rgb(255, 255, 255);font-family:simhei;</string>
</property>
<property name="text">
<string>13:20:00 2.4G检测到可疑目标(信号55)</string>
</property>
</widget>
<widget class="QLabel" name="Text_Q6">
<property name="geometry">
<rect>
<x>640</x>
<y>395</y>
<width>220</width>
<height>25</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font-size:11pt;color: rgb(255, 255, 255);font-family:simhei;</string>
</property>
<property name="text">
<string>13:20:00 2.4G检测到可疑目标(信号55)</string>
</property>
</widget>
<widget class="QLabel" name="Text_Q5">
<property name="geometry">
<rect>
<x>640</x>
<y>420</y>
<width>220</width>
<height>25</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font-size:11pt;color: rgb(255, 255, 255);font-family:simhei;</string>
</property>
<property name="text">
<string>13:20:00 2.4G检测到可疑目标(信号55)</string>
</property>
</widget>
<widget class="QLabel" name="Text_Q4">
<property name="geometry">
<rect>
<x>640</x>
<y>445</y>
<width>220</width>
<height>25</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font-size:11pt;color: rgb(255, 255, 255);font-family:simhei;</string>
</property>
<property name="text">
<string>13:20:00 2.4G检测到可疑目标(信号55)</string>
</property>
</widget>
<widget class="QLabel" name="Text_Q3">
<property name="geometry">
<rect>
<x>640</x>
<y>470</y>
<width>220</width>
<height>25</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font-size:11pt;color: rgb(255, 255, 255);font-family:simhei;</string>
</property>
<property name="text">
<string>13:20:00 2.4G检测到可疑目标(信号55)</string>
</property>
</widget>
<widget class="QLabel" name="Text_Q2">
<property name="geometry">
<rect>
<x>640</x>
<y>495</y>
<width>220</width>
<height>25</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font-size:11pt;color: rgb(255, 255, 255);font-family:simhei;</string>
</property>
<property name="text">
<string>13:20:00 2.4G检测到可疑目标(信号55)</string>
</property>
</widget>
<widget class="QLabel" name="Text_Q1">
<property name="geometry">
<rect>
<x>640</x>
<y>520</y>
<width>220</width>
<height>25</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);font-family:simhei;font-size:11pt;</string>
</property>
<property name="text">
<string>13:20:00 2.4G检测到可疑目标(信号55)</string>
</property>
</widget>
<widget class="QLabel" name="Text_Q0">
<property name="geometry">
<rect>
<x>640</x>
<y>545</y>
<width>220</width>
<height>25</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);font-family:simhei;font-size:11pt;</string>
</property>
<property name="text">
<string>13:20:00 2.4G检测到可疑目标(信号55)</string>
</property>
</widget>
<widget class="QPushButton" name="test_btn">
<property name="geometry">
<rect>
<x>550</x>
<y>10</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string>测试</string>
</property>
</widget>
<zorder>bkground</zorder>
<zorder>labelTableText</zorder>
<zorder>label_line2</zorder>
<zorder>X_roller</zorder>
<zorder>scale</zorder>
<zorder>scale_zero</zorder>
<zorder>scale_half_min</zorder>
<zorder>scale_min</zorder>
<zorder>x_800CDMA</zorder>
<zorder>x_900GSM</zorder>
<zorder>x_1800DCS</zorder>
<zorder>x_2100WCDMA</zorder>
<zorder>x_B41LTE</zorder>
<zorder>x_2GWIFI</zorder>
<zorder>X_roller_2</zorder>
<zorder>X_roller_3</zorder>
<zorder>X_roller_4</zorder>
<zorder>X_roller_5</zorder>
<zorder>X_roller_6</zorder>
<zorder>X_roller_7</zorder>
<zorder>X_roller_8</zorder>
<zorder>X_roller_9</zorder>
<zorder>X_roller_10</zorder>
<zorder>X_roller_11</zorder>
<zorder>Y_roller</zorder>
<zorder>scale_02</zorder>
<zorder>scale_04</zorder>
<zorder>Text_Q19</zorder>
<zorder>Text_Q18</zorder>
<zorder>Text_Q17</zorder>
<zorder>Text_Q16</zorder>
<zorder>Text_Q15</zorder>
<zorder>Text_Q14</zorder>
<zorder>Text_Q13</zorder>
<zorder>Text_Q12</zorder>
<zorder>Text_Q11</zorder>
<zorder>Text_Q10</zorder>
<zorder>Text_Q9</zorder>
<zorder>Text_Q8</zorder>
<zorder>Text_Q7</zorder>
<zorder>Text_Q6</zorder>
<zorder>Text_Q5</zorder>
<zorder>Text_Q4</zorder>
<zorder>Text_Q3</zorder>
<zorder>Text_Q2</zorder>
<zorder>Text_Q1</zorder>
<zorder>Text_Q0</zorder>
<zorder>test_btn</zorder>
</widget>
<resources/>
<connections/>
</ui>
以上代码仅供参考,还需要大量优化保证实时显示,如果觉得有帮助,还请一键三连支持一下~