在QStackedWidget中按钮跳转页面出错 求解答

时间:2022-11-09 18:02:42
源程序一个pushbutton对应一个页面  安按钮后跳转到一个页面。
我在源程序QStackedWidget中额外增加一页   额外添加了一个按钮 
按钮的槽函数加了一句  ui->stackedWidget->setCurrentIndex(7);
程序烧录到开发板后 其他按钮都不能正确跳转到原来的页面 
求大神解答

4 个解决方案

#1


是不是被你从QStackedWidget移除掉了

#2


没有啊 下帖我粘贴源程序

#3


#ifndef MAINWIDGET_H
#define MAINWIDGET_H

#include <QWidget>
#include <QSignalMapper>
#include <QPushButton>
#include <QList>
#include <QTextCodec>
#include <QTimer>
#include <QLabel>
#include <QGraphicsScene>
//#include <QPalette>
#include <QPointer>
#include <QMovie>
#include "getdatathread.h"
#include "mywindow.h"
#include "fan.h"
#include "fader.h"
#include "armvideo.h"
#include "autoctrl.h"


#define MTR(x) code->toUnicode(x)

namespace Ui {
    class MainWidget;
}

class MainWidget : public QWidget
{
    Q_OBJECT

public:
    explicit MainWidget(QWidget *parent = 0);
    ~MainWidget();

private slots:

    void on_pushButton_2_clicked();

    void on_pushButton_4_clicked();

    void on_pushButton_clicked();

    void on_CO2_clicked();

    void on_Humiture_clicked();

    void on_Sleet_clicked();

    void onBtn_clicked(int btn);

    void on_pushButton_3_clicked();

    void on_pushButton_12_clicked();

    void on_pushButton_5_clicked();

    void realTime_status_update();

    void realTime_status_check();

    void node_status_check();

    void fan_on();

    void videoDisplay();

    void fadeInWidget(int index);

    void on_pushButton_18_clicked();

    void on_pushButton_19_clicked();

    void on_pushButton_13_clicked();

    void on_pushButton_14_clicked();

    void on_pushButton_10_clicked();

    void on_pushButton_6_clicked();

    void on_pushButton_16_clicked();

    void on_pushButton_11_clicked();

    void on_pushButton_8_clicked();

    void on_pushButton_9_clicked();

    void on_pushButton_17_clicked();

    void on_pushButton_15_clicked();

    void on_pushButton_7_clicked();

    void on_pushButton_20_clicked();

private:
    Ui::MainWidget *ui;

    QTextCodec *code;
    QGraphicsScene *scene_f, *scene_w, *scene_a;

    Fan *dynamic_fan;

    MyWindow *dynamic_window;

    QMovie *movie;

    AutoCtrl *autoctrl;


    QSignalMapper *signalMapper;
    QList<QPushButton *> allNumButtons;
    QPointer<FaderWidget> faderWidget;

    void initPad();
    void node_on_status(int row, int column, QLabel *label);
    void node_off_status(int row, int column, QLabel *label);
    void node_status_change(int status, int row, int column, QLabel *label);

public:
    QTimer *status_timer, *check_timer, *node_timer, *fan_timer, *window_timer, *video_timer;
    GetDataThread *getdatathread;
    armVideo *armvideo;
    //QPalette pe;
};

#endif // MAINWIDGET_H

#4


#include "mainwidget.h"
#include "ui_mainwidget.h"
#include "tty.h"
#include "variable.h"
#include <termios.h>
#include <QKeyEvent>
#include <QMessageBox>
#include <QSplashScreen>

int fd;

int light_flag;
int window_flag = 1;
int waterpump_flag;
int fan_flag;
int mark;
int video_flag;
int video_status;
int video_creat;
int video_destroy = 1;

unsigned char buf[5];//5

MainWidget::MainWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MainWidget)
{
    ui->setupUi(this);

    QPalette bg_palette=this->palette();
    bg_palette.setBrush(QPalette::Window,QBrush(QPixmap(":/images/bg.jpg")));
    this->setPalette(bg_palette);
    this->setAutoFillBackground(true);

    ui->stackedWidget->setCurrentIndex(0);
    //ui->stackedWidget->setCurrentIndex(0);
    ui->CO2->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->Humiture->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->Sleet->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton->setStyleSheet("border-image: url(:/images/current.png)");
    ui->pushButton_11->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_16->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_20->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    code = QTextCodec::codecForName("GB2312");

    tty_init(&fd, "/dev/ttySAC2", B9600);

    getdatathread = new GetDataThread();
    getdatathread->start();

    scene_f = new QGraphicsScene;
    scene_f->setSceneRect(-24,-24,48,48);
    dynamic_fan = new Fan;
    dynamic_fan->setPos(0,0);
    scene_f->addItem(dynamic_fan);

    ui->gView_fan->setScene(scene_f);

    scene_w = new QGraphicsScene;
    scene_w->setSceneRect(96,-24,48,48);
    dynamic_window = new MyWindow;
    dynamic_window->setPos(0,2);
    scene_w->addItem(dynamic_window);

    ui->gView_window->setScene(scene_w);

    scene_a = new QGraphicsScene;
    scene_a->setSceneRect(-24,-24,48,48);
    autoctrl = new AutoCtrl;
    autoctrl->setPos(1,0);
    scene_a->addItem(autoctrl);

    ui->gView_auto->setScene(scene_a);


    status_timer = new QTimer();
    connect(status_timer, SIGNAL(timeout()), this, SLOT(realTime_status_update()));

    check_timer = new QTimer();
    connect(check_timer, SIGNAL(timeout()), this, SLOT(realTime_status_check()));

    node_timer = new QTimer();
    connect(node_timer, SIGNAL(timeout()), this, SLOT(node_status_check()));

    fan_timer = new QTimer();
    connect(fan_timer, SIGNAL(timeout()), this, SLOT(fan_on()));

    video_timer = new QTimer();
    movie = new QMovie;
    connect(video_timer, SIGNAL(timeout()), this, SLOT(videoDisplay()));

    connect(ui->stackedWidget, SIGNAL(currentChanged(int)), this, SLOT(fadeInWidget(int)));

    status_timer->start(1000);
    node_timer->start(1000);

    initPad();
    node_coor = 1;
}

MainWidget::~MainWidget()
{
    tty_end(fd);
    delete ui;
}

void MainWidget::on_pushButton_2_clicked()
{
    if(ui->pushButton_3->isChecked()){
        QMessageBox::critical(this,"Error",MTR("请先停止自动控制!"));
        return;
    }else{
        ui->stackedWidget->setCurrentIndex(1);
    }
}

void MainWidget::on_pushButton_4_clicked()
{
    ui->stackedWidget->setCurrentIndex(0);
    ui->label_51->setText(ui->lineEdit->text());
    ui->label_54->setText(ui->lineEdit_2->text());
    ui->label_57->setText(ui->lineEdit_4->text());
    ui->label_60->setText(ui->lineEdit_3->text());
    ui->label_63->setText(ui->lineEdit_6->text());
    ui->label_66->setText(ui->lineEdit_5->text());
    ui->label_69->setText(ui->lineEdit_7->text());
    ui->lineEdit->clear();
    ui->lineEdit_2->clear();
    ui->lineEdit_3->clear();
    ui->lineEdit_4->clear();
    ui->lineEdit_5->clear();
    ui->lineEdit_6->clear();
    ui->lineEdit_7->clear();
    ui->CO2->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->Humiture->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->Sleet->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton->setStyleSheet("border-image: url(:/images/current.png)");
    ui->pushButton_11->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_16->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_20->setStyleSheet("border-image: url(:/images/mainbutton.png)");
}

void MainWidget::on_pushButton_clicked()
{
    if(video_flag == 1){
        QMessageBox::critical(this,"Error",MTR("请关闭视频监控!"));
        return;
    }
    ui->stackedWidget->setCurrentIndex(0);
    ui->CO2->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->Humiture->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->Sleet->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton->setStyleSheet("border-image: url(:/images/current.png)");
    ui->pushButton_11->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_16->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_20->setStyleSheet("border-image: url(:/images/mainbutton.png)");
}

void MainWidget::on_CO2_clicked()
{
    if(video_flag == 1){
        QMessageBox::critical(this,"Error",MTR("请关闭视频监控!"));
        return;
    }
    ui->stackedWidget->setCurrentIndex(2);
    ui->CO2->setStyleSheet("border-image: url(:/images/current.png)");
    ui->Humiture->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->Sleet->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_11->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_16->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_20->setStyleSheet("border-image: url(:/images/mainbutton.png)");
}

void MainWidget::on_Humiture_clicked()
{
    if(video_flag == 1)
    {
        QMessageBox::critical(this,"Error",MTR("请关闭视频监控!"));
        return;
    }
    ui->stackedWidget->setCurrentIndex(4);
    ui->CO2->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->Humiture->setStyleSheet("border-image: url(:/images/current.png)");
    ui->Sleet->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_11->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_16->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_20->setStyleSheet("border-image: url(:/images/mainbutton.png)");
}

void MainWidget::on_Sleet_clicked()
{
    if(video_flag == 1){
        QMessageBox::critical(this,"Error",MTR("请关闭视频监控!"));
        return;
    }
    ui->stackedWidget->setCurrentIndex(3);
    ui->CO2->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->Humiture->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->Sleet->setStyleSheet("border-image: url(:/images/current.png)");
    ui->pushButton->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_11->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_16->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_20->setStyleSheet("border-image: url(:/images/mainbutton.png)"); }

void MainWidget::initPad()
{
    // use for button pad
    signalMapper = new QSignalMapper(this);
    allNumButtons = ui->frame_13->findChildren<QPushButton *>();
    for (int i=0 ; i<allNumButtons.count() ; i++) {
        connect(allNumButtons.at(i), SIGNAL(clicked()), signalMapper, SLOT(map()));
        signalMapper->setMapping(allNumButtons.at(i), i);
    }
    connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(onBtn_clicked(int)));
}

void MainWidget::onBtn_clicked(int btn)
{
    QString strKeyId;
    strKeyId = allNumButtons.at(btn)->accessibleName();
    //qDebug() << "num= " << btn << "id= "<<strKeyId;
    bool isOk;
    int keyId = strKeyId.toInt(&isOk, 16);
    //if (strKeyId.isEmpty() || !isOk) {
    //    QMessageBox::information(0,0,"Key Not Found");
    //    return;
    //}
    //qDebug() << "text= " << allNumButtons.at(btn)->text();
    QString ch = allNumButtons.at(btn)->text().trimmed();
    //qDebug() << "text= " << allNumButtons.at(btn)->text().trimmed();
    QKeyEvent keyEvent(QEvent::KeyPress, keyId, Qt::NoModifier, ch, false, 1);
    if(btn !=4){
        if(ui->lineEdit->hasFocus())
            QApplication::sendEvent(ui->lineEdit, &keyEvent);
        else if(ui->lineEdit_2->hasFocus())
            QApplication::sendEvent(ui->lineEdit_2, &keyEvent);
        else if(ui->lineEdit_3->hasFocus())
            QApplication::sendEvent(ui->lineEdit_3, &keyEvent);
        else if(ui->lineEdit_4->hasFocus())
            QApplication::sendEvent(ui->lineEdit_4, &keyEvent);
        else if(ui->lineEdit_5->hasFocus())
            QApplication::sendEvent(ui->lineEdit_5, &keyEvent);
        else if(ui->lineEdit_6->hasFocus())
            QApplication::sendEvent(ui->lineEdit_6, &keyEvent);
        else if(ui->lineEdit_7->hasFocus())
            QApplication::sendEvent(ui->lineEdit_7, &keyEvent);
    }
    if(btn == 4){
        if(ui->lineEdit->hasFocus())
            ui->lineEdit->backspace();
        else if(ui->lineEdit_2->hasFocus())
            ui->lineEdit_2->backspace();
        else if(ui->lineEdit_3->hasFocus())
            ui->lineEdit_3->backspace();
        else if(ui->lineEdit_4->hasFocus())
            ui->lineEdit_4->backspace();
        else if(ui->lineEdit_5->hasFocus())
            ui->lineEdit_5->backspace();
        else if(ui->lineEdit_6->hasFocus())
            ui->lineEdit_6->backspace();
        else if(ui->lineEdit_7->hasFocus())
            ui->lineEdit_7->backspace();
    }

}


#1


是不是被你从QStackedWidget移除掉了

#2


没有啊 下帖我粘贴源程序

#3


#ifndef MAINWIDGET_H
#define MAINWIDGET_H

#include <QWidget>
#include <QSignalMapper>
#include <QPushButton>
#include <QList>
#include <QTextCodec>
#include <QTimer>
#include <QLabel>
#include <QGraphicsScene>
//#include <QPalette>
#include <QPointer>
#include <QMovie>
#include "getdatathread.h"
#include "mywindow.h"
#include "fan.h"
#include "fader.h"
#include "armvideo.h"
#include "autoctrl.h"


#define MTR(x) code->toUnicode(x)

namespace Ui {
    class MainWidget;
}

class MainWidget : public QWidget
{
    Q_OBJECT

public:
    explicit MainWidget(QWidget *parent = 0);
    ~MainWidget();

private slots:

    void on_pushButton_2_clicked();

    void on_pushButton_4_clicked();

    void on_pushButton_clicked();

    void on_CO2_clicked();

    void on_Humiture_clicked();

    void on_Sleet_clicked();

    void onBtn_clicked(int btn);

    void on_pushButton_3_clicked();

    void on_pushButton_12_clicked();

    void on_pushButton_5_clicked();

    void realTime_status_update();

    void realTime_status_check();

    void node_status_check();

    void fan_on();

    void videoDisplay();

    void fadeInWidget(int index);

    void on_pushButton_18_clicked();

    void on_pushButton_19_clicked();

    void on_pushButton_13_clicked();

    void on_pushButton_14_clicked();

    void on_pushButton_10_clicked();

    void on_pushButton_6_clicked();

    void on_pushButton_16_clicked();

    void on_pushButton_11_clicked();

    void on_pushButton_8_clicked();

    void on_pushButton_9_clicked();

    void on_pushButton_17_clicked();

    void on_pushButton_15_clicked();

    void on_pushButton_7_clicked();

    void on_pushButton_20_clicked();

private:
    Ui::MainWidget *ui;

    QTextCodec *code;
    QGraphicsScene *scene_f, *scene_w, *scene_a;

    Fan *dynamic_fan;

    MyWindow *dynamic_window;

    QMovie *movie;

    AutoCtrl *autoctrl;


    QSignalMapper *signalMapper;
    QList<QPushButton *> allNumButtons;
    QPointer<FaderWidget> faderWidget;

    void initPad();
    void node_on_status(int row, int column, QLabel *label);
    void node_off_status(int row, int column, QLabel *label);
    void node_status_change(int status, int row, int column, QLabel *label);

public:
    QTimer *status_timer, *check_timer, *node_timer, *fan_timer, *window_timer, *video_timer;
    GetDataThread *getdatathread;
    armVideo *armvideo;
    //QPalette pe;
};

#endif // MAINWIDGET_H

#4


#include "mainwidget.h"
#include "ui_mainwidget.h"
#include "tty.h"
#include "variable.h"
#include <termios.h>
#include <QKeyEvent>
#include <QMessageBox>
#include <QSplashScreen>

int fd;

int light_flag;
int window_flag = 1;
int waterpump_flag;
int fan_flag;
int mark;
int video_flag;
int video_status;
int video_creat;
int video_destroy = 1;

unsigned char buf[5];//5

MainWidget::MainWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MainWidget)
{
    ui->setupUi(this);

    QPalette bg_palette=this->palette();
    bg_palette.setBrush(QPalette::Window,QBrush(QPixmap(":/images/bg.jpg")));
    this->setPalette(bg_palette);
    this->setAutoFillBackground(true);

    ui->stackedWidget->setCurrentIndex(0);
    //ui->stackedWidget->setCurrentIndex(0);
    ui->CO2->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->Humiture->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->Sleet->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton->setStyleSheet("border-image: url(:/images/current.png)");
    ui->pushButton_11->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_16->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_20->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    code = QTextCodec::codecForName("GB2312");

    tty_init(&fd, "/dev/ttySAC2", B9600);

    getdatathread = new GetDataThread();
    getdatathread->start();

    scene_f = new QGraphicsScene;
    scene_f->setSceneRect(-24,-24,48,48);
    dynamic_fan = new Fan;
    dynamic_fan->setPos(0,0);
    scene_f->addItem(dynamic_fan);

    ui->gView_fan->setScene(scene_f);

    scene_w = new QGraphicsScene;
    scene_w->setSceneRect(96,-24,48,48);
    dynamic_window = new MyWindow;
    dynamic_window->setPos(0,2);
    scene_w->addItem(dynamic_window);

    ui->gView_window->setScene(scene_w);

    scene_a = new QGraphicsScene;
    scene_a->setSceneRect(-24,-24,48,48);
    autoctrl = new AutoCtrl;
    autoctrl->setPos(1,0);
    scene_a->addItem(autoctrl);

    ui->gView_auto->setScene(scene_a);


    status_timer = new QTimer();
    connect(status_timer, SIGNAL(timeout()), this, SLOT(realTime_status_update()));

    check_timer = new QTimer();
    connect(check_timer, SIGNAL(timeout()), this, SLOT(realTime_status_check()));

    node_timer = new QTimer();
    connect(node_timer, SIGNAL(timeout()), this, SLOT(node_status_check()));

    fan_timer = new QTimer();
    connect(fan_timer, SIGNAL(timeout()), this, SLOT(fan_on()));

    video_timer = new QTimer();
    movie = new QMovie;
    connect(video_timer, SIGNAL(timeout()), this, SLOT(videoDisplay()));

    connect(ui->stackedWidget, SIGNAL(currentChanged(int)), this, SLOT(fadeInWidget(int)));

    status_timer->start(1000);
    node_timer->start(1000);

    initPad();
    node_coor = 1;
}

MainWidget::~MainWidget()
{
    tty_end(fd);
    delete ui;
}

void MainWidget::on_pushButton_2_clicked()
{
    if(ui->pushButton_3->isChecked()){
        QMessageBox::critical(this,"Error",MTR("请先停止自动控制!"));
        return;
    }else{
        ui->stackedWidget->setCurrentIndex(1);
    }
}

void MainWidget::on_pushButton_4_clicked()
{
    ui->stackedWidget->setCurrentIndex(0);
    ui->label_51->setText(ui->lineEdit->text());
    ui->label_54->setText(ui->lineEdit_2->text());
    ui->label_57->setText(ui->lineEdit_4->text());
    ui->label_60->setText(ui->lineEdit_3->text());
    ui->label_63->setText(ui->lineEdit_6->text());
    ui->label_66->setText(ui->lineEdit_5->text());
    ui->label_69->setText(ui->lineEdit_7->text());
    ui->lineEdit->clear();
    ui->lineEdit_2->clear();
    ui->lineEdit_3->clear();
    ui->lineEdit_4->clear();
    ui->lineEdit_5->clear();
    ui->lineEdit_6->clear();
    ui->lineEdit_7->clear();
    ui->CO2->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->Humiture->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->Sleet->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton->setStyleSheet("border-image: url(:/images/current.png)");
    ui->pushButton_11->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_16->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_20->setStyleSheet("border-image: url(:/images/mainbutton.png)");
}

void MainWidget::on_pushButton_clicked()
{
    if(video_flag == 1){
        QMessageBox::critical(this,"Error",MTR("请关闭视频监控!"));
        return;
    }
    ui->stackedWidget->setCurrentIndex(0);
    ui->CO2->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->Humiture->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->Sleet->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton->setStyleSheet("border-image: url(:/images/current.png)");
    ui->pushButton_11->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_16->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_20->setStyleSheet("border-image: url(:/images/mainbutton.png)");
}

void MainWidget::on_CO2_clicked()
{
    if(video_flag == 1){
        QMessageBox::critical(this,"Error",MTR("请关闭视频监控!"));
        return;
    }
    ui->stackedWidget->setCurrentIndex(2);
    ui->CO2->setStyleSheet("border-image: url(:/images/current.png)");
    ui->Humiture->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->Sleet->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_11->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_16->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_20->setStyleSheet("border-image: url(:/images/mainbutton.png)");
}

void MainWidget::on_Humiture_clicked()
{
    if(video_flag == 1)
    {
        QMessageBox::critical(this,"Error",MTR("请关闭视频监控!"));
        return;
    }
    ui->stackedWidget->setCurrentIndex(4);
    ui->CO2->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->Humiture->setStyleSheet("border-image: url(:/images/current.png)");
    ui->Sleet->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_11->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_16->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_20->setStyleSheet("border-image: url(:/images/mainbutton.png)");
}

void MainWidget::on_Sleet_clicked()
{
    if(video_flag == 1){
        QMessageBox::critical(this,"Error",MTR("请关闭视频监控!"));
        return;
    }
    ui->stackedWidget->setCurrentIndex(3);
    ui->CO2->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->Humiture->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->Sleet->setStyleSheet("border-image: url(:/images/current.png)");
    ui->pushButton->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_11->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_16->setStyleSheet("border-image: url(:/images/mainbutton.png)");
    ui->pushButton_20->setStyleSheet("border-image: url(:/images/mainbutton.png)"); }

void MainWidget::initPad()
{
    // use for button pad
    signalMapper = new QSignalMapper(this);
    allNumButtons = ui->frame_13->findChildren<QPushButton *>();
    for (int i=0 ; i<allNumButtons.count() ; i++) {
        connect(allNumButtons.at(i), SIGNAL(clicked()), signalMapper, SLOT(map()));
        signalMapper->setMapping(allNumButtons.at(i), i);
    }
    connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(onBtn_clicked(int)));
}

void MainWidget::onBtn_clicked(int btn)
{
    QString strKeyId;
    strKeyId = allNumButtons.at(btn)->accessibleName();
    //qDebug() << "num= " << btn << "id= "<<strKeyId;
    bool isOk;
    int keyId = strKeyId.toInt(&isOk, 16);
    //if (strKeyId.isEmpty() || !isOk) {
    //    QMessageBox::information(0,0,"Key Not Found");
    //    return;
    //}
    //qDebug() << "text= " << allNumButtons.at(btn)->text();
    QString ch = allNumButtons.at(btn)->text().trimmed();
    //qDebug() << "text= " << allNumButtons.at(btn)->text().trimmed();
    QKeyEvent keyEvent(QEvent::KeyPress, keyId, Qt::NoModifier, ch, false, 1);
    if(btn !=4){
        if(ui->lineEdit->hasFocus())
            QApplication::sendEvent(ui->lineEdit, &keyEvent);
        else if(ui->lineEdit_2->hasFocus())
            QApplication::sendEvent(ui->lineEdit_2, &keyEvent);
        else if(ui->lineEdit_3->hasFocus())
            QApplication::sendEvent(ui->lineEdit_3, &keyEvent);
        else if(ui->lineEdit_4->hasFocus())
            QApplication::sendEvent(ui->lineEdit_4, &keyEvent);
        else if(ui->lineEdit_5->hasFocus())
            QApplication::sendEvent(ui->lineEdit_5, &keyEvent);
        else if(ui->lineEdit_6->hasFocus())
            QApplication::sendEvent(ui->lineEdit_6, &keyEvent);
        else if(ui->lineEdit_7->hasFocus())
            QApplication::sendEvent(ui->lineEdit_7, &keyEvent);
    }
    if(btn == 4){
        if(ui->lineEdit->hasFocus())
            ui->lineEdit->backspace();
        else if(ui->lineEdit_2->hasFocus())
            ui->lineEdit_2->backspace();
        else if(ui->lineEdit_3->hasFocus())
            ui->lineEdit_3->backspace();
        else if(ui->lineEdit_4->hasFocus())
            ui->lineEdit_4->backspace();
        else if(ui->lineEdit_5->hasFocus())
            ui->lineEdit_5->backspace();
        else if(ui->lineEdit_6->hasFocus())
            ui->lineEdit_6->backspace();
        else if(ui->lineEdit_7->hasFocus())
            ui->lineEdit_7->backspace();
    }

}