#include "MainWnd.h" #include "ui_MainWnd.h" #include "Login.h" #include #include #include "OriginalWnd/OriginalWnd.h" MainWnd::MainWnd(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWnd) { ui->setupUi(this); initForm(); } MainWnd::~MainWnd() { delete ui; } void MainWnd::initForm() { // 隐藏原生标题栏 setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog); // 窗口背景透明 setAttribute(Qt::WA_TranslucentBackground, true); QPixmap pixmap(":/images/light/logo1.png"); QPixmap scaledPixmap = pixmap.scaled(90, 49, Qt::KeepAspectRatio); ui->label_logo->setPixmap(scaledPixmap); Login *login = new Login; ui->stackedWidget_UI->addWidget(login); ui->stackedWidget_UI->setCurrentIndex(ui->stackedWidget_UI->indexOf(login)); //登录监听 ui->label_logo->installEventFilter(this); ui->stackedWidget_UI->installEventFilter(this); //安装监听事件,点击左侧按钮图标变化 ui->tabHomeBtn->installEventFilter(this); ui->tabProductionBtn->installEventFilter(this); ui->tabProgramBtn->installEventFilter(this); ui->tabMessageBtn->installEventFilter(this); ui->tabModuleBtn->installEventFilter(this); ui->tabDispositionBtn->installEventFilter(this); ui->tabDiagnosisBtn->installEventFilter(this); ui->tabSystemBtn->installEventFilter(this); ui->tabHelpBtn->installEventFilter(this); } bool MainWnd::eventFilter(QObject *obj, QEvent *event) { if (obj == this->ui->stackedWidget_UI) { onCurrentWidgetChanged(); } if (obj == this->ui->label_logo) { //判断事件类型是否为鼠标事件 if (event->type() == QEvent::MouseButtonPress) { //转换为鼠标事件 QMouseEvent* mouseenevt = static_cast(event); //判断鼠标左键点击 if (mouseenevt->button() == Qt::LeftButton) { Login *login = new Login; ui->stackedWidget_UI->addWidget(login); ui->stackedWidget_UI->setCurrentIndex(ui->stackedWidget_UI->indexOf(login)); return true; } } } switch(event->type()) { case QEvent::MouseButtonPress: { if(obj == ui->tabHomeBtn && ui->tabHomeBtn->isEnabled()) { ui->tabHomeBtn->setIcon(QIcon(":/images/deep/home.png")); ui->tabHomeBtn->setChecked(true); if(ui->tabProductionBtn->isChecked() == false) { ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png")); } if(ui->tabProgramBtn->isChecked() == false) { ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png")); } if(ui->tabMessageBtn->isChecked() == false) { ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png")); } if(ui->tabModuleBtn->isChecked() == false) { ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png")); } if(ui->tabDispositionBtn->isChecked() == false) { ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png")); } if(ui->tabDiagnosisBtn->isChecked() == false) { ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png")); } if(ui->tabSystemBtn->isChecked() == false) { ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png")); } if(ui->tabHelpBtn->isChecked() == false) { ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png")); } } if(obj == ui->tabProductionBtn && ui->tabProductionBtn->isEnabled()) { ui->tabProductionBtn->setIcon(QIcon(":/images/deep/Productionn assistance.png")); ui->tabProductionBtn->setChecked(true); if(ui->tabHomeBtn->isChecked() == false) { ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png")); } if(ui->tabProgramBtn->isChecked() == false) { ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png")); } if(ui->tabMessageBtn->isChecked() == false) { ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png")); } if(ui->tabModuleBtn->isChecked() == false) { ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png")); } if(ui->tabDispositionBtn->isChecked() == false) { ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png")); } if(ui->tabDiagnosisBtn->isChecked() == false) { ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png")); } if(ui->tabSystemBtn->isChecked() == false) { ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png")); } if(ui->tabHelpBtn->isChecked() == false) { ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png")); } } if(obj == ui->tabProgramBtn && ui->tabProgramBtn->isEnabled()) { ui->tabProgramBtn->setIcon(QIcon(":/images/deep/Program.png")); ui->tabProgramBtn->setChecked(true); if(ui->tabHomeBtn->isChecked() == false) { ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png")); } if(ui->tabProductionBtn->isChecked() == false) { ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png")); } if(ui->tabMessageBtn->isChecked() == false) { ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png")); } if(ui->tabModuleBtn->isChecked() == false) { ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png")); } if(ui->tabDispositionBtn->isChecked() == false) { ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png")); } if(ui->tabDiagnosisBtn->isChecked() == false) { ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png")); } if(ui->tabSystemBtn->isChecked() == false) { ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png")); } if(ui->tabHelpBtn->isChecked() == false) { ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png")); } } if(obj == ui->tabMessageBtn && ui->tabMessageBtn->isEnabled()) { ui->tabMessageBtn->setIcon(QIcon(":/images/deep/Message.png")); ui->tabMessageBtn->setChecked(true); if(ui->tabHomeBtn->isChecked() == false) { ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png")); } if(ui->tabProductionBtn->isChecked() == false) { ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png")); } if(ui->tabProgramBtn->isChecked() == false) { ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png")); } if(ui->tabModuleBtn->isChecked() == false) { ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png")); } if(ui->tabDispositionBtn->isChecked() == false) { ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png")); } if(ui->tabDiagnosisBtn->isChecked() == false) { ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png")); } if(ui->tabSystemBtn->isChecked() == false) { ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png")); } if(ui->tabHelpBtn->isChecked() == false) { ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png")); } } if(obj == ui->tabModuleBtn && ui->tabModuleBtn->isEnabled()) { ui->tabModuleBtn->setIcon(QIcon(":/images/deep/Module.png")); ui->tabModuleBtn->setChecked(true); if(ui->tabHomeBtn->isChecked() == false) { ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png")); } if(ui->tabProductionBtn->isChecked() == false) { ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png")); } if(ui->tabProgramBtn->isChecked() == false) { ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png")); } if(ui->tabMessageBtn->isChecked() == false) { ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png")); } if(ui->tabDispositionBtn->isChecked() == false) { ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png")); } if(ui->tabDiagnosisBtn->isChecked() == false) { ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png")); } if(ui->tabSystemBtn->isChecked() == false) { ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png")); } if(ui->tabHelpBtn->isChecked() == false) { ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png")); } } if(obj == ui->tabDispositionBtn && ui->tabDispositionBtn->isEnabled()) { ui->tabDispositionBtn->setIcon(QIcon(":/images/deep/Disposition.png")); ui->tabDispositionBtn->setChecked(true); if(ui->tabHomeBtn->isChecked() == false) { ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png")); } if(ui->tabProductionBtn->isChecked() == false) { ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png")); } if(ui->tabProgramBtn->isChecked() == false) { ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png")); } if(ui->tabMessageBtn->isChecked() == false) { ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png")); } if(ui->tabModuleBtn->isChecked() == false) { ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png")); } if(ui->tabDiagnosisBtn->isChecked() == false) { ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png")); } if(ui->tabSystemBtn->isChecked() == false) { ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png")); } if(ui->tabHelpBtn->isChecked() == false) { ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png")); } } if(obj == ui->tabDiagnosisBtn && ui->tabDiagnosisBtn->isEnabled()) { ui->tabDiagnosisBtn->setIcon(QIcon(":/images/deep/Diagnosis.png")); ui->tabDiagnosisBtn->setChecked(true); if(ui->tabHomeBtn->isChecked() == false) { ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png")); } if(ui->tabProductionBtn->isChecked() == false) { ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png")); } if(ui->tabProgramBtn->isChecked() == false) { ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png")); } if(ui->tabMessageBtn->isChecked() == false) { ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png")); } if(ui->tabModuleBtn->isChecked() == false) { ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png")); } if(ui->tabDispositionBtn->isChecked() == false) { ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png")); } if(ui->tabSystemBtn->isChecked() == false) { ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png")); } if(ui->tabHelpBtn->isChecked() == false) { ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png")); } } if(obj == ui->tabSystemBtn && ui->tabSystemBtn->isEnabled()) { ui->tabSystemBtn->setIcon(QIcon(":/images/deep/System.png")); ui->tabSystemBtn->setChecked(true); if(ui->tabHomeBtn->isChecked() == false) { ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png")); } if(ui->tabProductionBtn->isChecked() == false) { ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png")); } if(ui->tabProgramBtn->isChecked() == false) { ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png")); } if(ui->tabMessageBtn->isChecked() == false) { ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png")); } if(ui->tabModuleBtn->isChecked() == false) { ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png")); } if(ui->tabDispositionBtn->isChecked() == false) { ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png")); } if(ui->tabDiagnosisBtn->isChecked() == false) { ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png")); } if(ui->tabHelpBtn->isChecked() == false) { ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png")); } } if(obj == ui->tabHelpBtn && ui->tabHelpBtn->isEnabled()) { ui->tabHelpBtn->setIcon(QIcon(":/images/deep/Help.png")); ui->tabHelpBtn->setChecked(true); if(ui->tabHomeBtn->isChecked() == false) { ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png")); } if(ui->tabProductionBtn->isChecked() == false) { ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png")); } if(ui->tabProgramBtn->isChecked() == false) { ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png")); } if(ui->tabMessageBtn->isChecked() == false) { ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png")); } if(ui->tabModuleBtn->isChecked() == false) { ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png")); } if(ui->tabDispositionBtn->isChecked() == false) { ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png")); } if(ui->tabDiagnosisBtn->isChecked() == false) { ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png")); } if(ui->tabSystemBtn->isChecked() == false) { ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png")); } } break; } case QEvent::HoverEnter: { if(obj == ui->tabHomeBtn && ui->tabHomeBtn->isEnabled()) { ui->tabHomeBtn->setIcon(QIcon(":/images/deep/home.png")); } if(obj == ui->tabProductionBtn && ui->tabProductionBtn->isEnabled()) { ui->tabProductionBtn->setIcon(QIcon(":/images/deep/Productionn assistance.png")); } if(obj == ui->tabProgramBtn && ui->tabProgramBtn->isEnabled()) { ui->tabProgramBtn->setIcon(QIcon(":/images/deep/Program.png")); } if(obj == ui->tabMessageBtn && ui->tabMessageBtn->isEnabled()) { ui->tabMessageBtn->setIcon(QIcon(":/images/deep/Message.png")); } if(obj == ui->tabModuleBtn && ui->tabModuleBtn->isEnabled()) { ui->tabModuleBtn->setIcon(QIcon(":/images/deep/Module.png")); } if(obj == ui->tabDispositionBtn && ui->tabDispositionBtn->isEnabled()) { ui->tabDispositionBtn->setIcon(QIcon(":/images/deep/Disposition.png")); } if(obj == ui->tabDiagnosisBtn && ui->tabDiagnosisBtn->isEnabled()) { ui->tabDiagnosisBtn->setIcon(QIcon(":/images/deep/Diagnosis.png")); } if(obj == ui->tabSystemBtn && ui->tabSystemBtn->isEnabled()) { ui->tabSystemBtn->setIcon(QIcon(":/images/deep/System.png")); } if(obj == ui->tabHelpBtn && ui->tabHelpBtn->isEnabled()) { ui->tabHelpBtn->setIcon(QIcon(":/images/deep/Help.png")); } break; } case QEvent::HoverLeave: { if(obj == ui->tabHomeBtn && ui->tabHomeBtn->isChecked() == false) { ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png")); ui->tabHomeBtn->setChecked(false); } if(obj == ui->tabProductionBtn && ui->tabProductionBtn->isChecked() == false) { ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png")); ui->tabProductionBtn->setChecked(false); } if(obj == ui->tabProgramBtn && ui->tabProgramBtn->isChecked() == false) { ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png")); ui->tabProgramBtn->setChecked(false); } if(obj == ui->tabMessageBtn && ui->tabMessageBtn->isChecked() == false) { ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png")); ui->tabMessageBtn->setChecked(false); } if(obj == ui->tabModuleBtn && ui->tabModuleBtn->isChecked() == false) { ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png")); ui->tabModuleBtn->setChecked(false); } if(obj == ui->tabDispositionBtn && ui->tabDispositionBtn->isChecked() == false) { ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png")); ui->tabDispositionBtn->setChecked(false); } if(obj == ui->tabDiagnosisBtn && ui->tabDiagnosisBtn->isChecked() == false) { ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png")); ui->tabDiagnosisBtn->setChecked(false); } if(obj == ui->tabSystemBtn && ui->tabSystemBtn->isChecked() == false) { ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png")); ui->tabSystemBtn->setChecked(false); } if(obj == ui->tabHelpBtn && ui->tabHelpBtn->isChecked() == false) { ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png")); ui->tabHelpBtn->setChecked(false); } } default: break; } return QWidget::eventFilter(obj, event); } void MainWnd::onCurrentWidgetChanged() { QWidget *currentWidget = ui->stackedWidget_UI->currentWidget(); if (currentWidget) { QString currentWidgetName = currentWidget->objectName(); if (currentWidgetName == "Login") { QString styleSheet = "QToolButton:disabled { color: #808080; background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #F8FBFF, stop: 1 #E7ECF3); }"; // 设置禁用状态下的文本颜色为灰色 ui->tabHomeBtn->setDisabled(true); ui->tabHomeBtn->setStyleSheet(styleSheet); ui->tabProductionBtn->setDisabled(true); ui->tabProductionBtn->setStyleSheet(styleSheet); ui->tabProgramBtn->setDisabled(true); ui->tabProgramBtn->setStyleSheet(styleSheet); ui->tabMessageBtn->setDisabled(true); ui->tabMessageBtn->setStyleSheet(styleSheet); ui->tabModuleBtn->setDisabled(true); ui->tabModuleBtn->setStyleSheet(styleSheet); ui->tabDispositionBtn->setDisabled(true); ui->tabDispositionBtn->setStyleSheet(styleSheet); ui->tabDiagnosisBtn->setDisabled(true); ui->tabDiagnosisBtn->setStyleSheet(styleSheet); ui->tabSystemBtn->setDisabled(true); ui->tabSystemBtn->setStyleSheet(styleSheet); ui->tabHelpBtn->setDisabled(true); ui->tabHelpBtn->setStyleSheet(styleSheet); } else { ui->tabHomeBtn->setDisabled(false); ui->tabProductionBtn->setDisabled(false); ui->tabProgramBtn->setDisabled(false); ui->tabMessageBtn->setDisabled(false); ui->tabModuleBtn->setDisabled(false); ui->tabDispositionBtn->setDisabled(false); ui->tabDiagnosisBtn->setDisabled(false); ui->tabSystemBtn->setDisabled(false); ui->tabHelpBtn->setDisabled(false); } } } void MainWnd::on_tabHomeBtn_clicked() { // OriginalWnd *originalWnd = new OriginalWnd(this); // ui->stackedWidget_UI->addWidget(originalWnd); // ui->stackedWidget_UI->setCurrentIndex(ui->stackedWidget_UI->indexOf(originalWnd)); } void MainWnd::on_pushButton_clicked() { qApp->quit(); }