int main(int argc, char *argv[]) { QApplication a(argc, argv); QApplication::setStyle("plastique"); QTextCodec *codec = QTextCodec::codecForName("system"); QTextCodec::setCodecForLocale(codec); QTextCodec::setCodecForCStrings(codec); QTextCodec::setCodecForTr(codec); SystemSettings::getInstance(); QPixmap pixmap(":/jewelrySystem_JJ/Resources/loading.png"); QFont splashFont("Times", 10, QFont::Normal); QSplashScreen splash(pixmap); splash.setFont(splashFont); splash.showMessage(QObject::tr(" 正在加载............"),Qt::AlignBottom | Qt::AlignLeft, Qt::white); splash.show(); jewelryLogin login; qApp->processEvents(); MainSleep(4000); login.resize(400, 230); login.show(); splash.finish(&login); return a.exec(); }
MainPage::MainPage(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags) { ui.setupUi(this); this->LoadQSS(); m_mousePressed = false; QObject::connect(ui.toolButtonHardware, SIGNAL(clicked()), this, SLOT(HardwareInforClicked())); QObject::connect(ui.toolButtonTempManagement, SIGNAL(clicked()), this, SLOT(TemperatureClicked())); QObject::connect(ui.toolButtonTestItem, SIGNAL(clicked()), this, SLOT(TestItemClicked())); QObject::connect(ui.pushButtonMin, SIGNAL(clicked()), this, SLOT(MinButtonClicked())); QObject::connect(ui.pushButtonClose, SIGNAL(clicked()), this, SLOT(CloseButtonClicked())); QObject::connect(ui.pushButtonUpdate, SIGNAL(clicked()), this, SLOT(UpdateButtonClicked())); QObject::connect(&m_checkNewTimer, SIGNAL(timeout()), this, SLOT(CheckNewTimerTimeout())); QObject::connect(&m_downloadNewTimer, SIGNAL(timeout()), this, SLOT(DownloadNewTimerTimeout())); // 隐藏默认窗口边框和标题栏 this->setWindowFlags(Qt::Window|Qt::FramelessWindowHint|Qt::WindowSystemMenuHint |Qt::WindowMinimizeButtonHint|Qt::WindowMaximizeButtonHint); this->setWindowIcon(QIcon(":/ControlImage/Main.png")); QString title = MAIN_TITLE; title += LAppParam::GetAppVersion(); this->ui.labelTitle->setText(title); this->ui.pushButtonUpdate->setVisible(false); // 获取当前系统DPI, 当前系统DPI除以设计时DPI值, 则得到UI放大系数 const float DESIGN_DPI = 96.0f; // 设计时DPI QPainter painter(this); QPaintDevice* pDevice = painter.device(); PrintLogW(L"System DPI X: %d, Y: %d", pDevice->logicalDpiX(), pDevice->logicalDpiY()); float ratioX = pDevice->logicalDpiX()/DESIGN_DPI; float ratioY = pDevice->logicalDpiY()/DESIGN_DPI; m_uiRatio = ratioX > ratioY ? ratioX : ratioY; if (m_uiRatio < 1.0f) m_uiRatio = 1.0f; PrintLogW(L"UI Ratio: %f", m_uiRatio); // 根据比例重新调整主UI大小, 并居中显示 int width = this->geometry().width() * m_uiRatio; int height = this->geometry().height() * m_uiRatio; this->setFixedSize(width, height); QDesktopWidget* pDesk = QApplication::desktop(); this->move((pDesk->width() - width) / 2, (pDesk->height() - height) / 2); // 显示启动画面 QPixmap originalImage(".\\Image\\Background\\splash.png"); QSize imageSize(originalImage.width() * m_uiRatio, originalImage.height() * m_uiRatio); QPixmap scaledImage = originalImage.scaled(imageSize, Qt::KeepAspectRatio); QFont splashFont("Microsoft YaHei UI", 10); m_splashScreen.setFont(splashFont); m_splashScreen.setPixmap(scaledImage); m_splashScreen.show(); width = ui.stackedWidget->width() * m_uiRatio; height = ui.stackedWidget->height() * m_uiRatio; m_splashScreen.showMessage(QObject::tr("Creating Hardware Page..."), Qt::AlignLeft | Qt::AlignTop, Qt::red); m_pHardwareInforPage = new HardwareInforPage(m_uiRatio); m_pHardwareInforPage->SetSplashScreen(&m_splashScreen); m_pHardwareInforPage->setFixedSize(width, height); m_pHardwareInforPage->InitHardwareInfor(); ui.stackedWidget->addWidget(m_pHardwareInforPage); m_splashScreen.showMessage(QObject::tr("Creating Temperature Page..."), Qt::AlignLeft | Qt::AlignTop, Qt::red); m_pTempManagementPage = new TempManagementPage(); m_pTempManagementPage->setFixedSize(width, height); ui.stackedWidget->addWidget(m_pTempManagementPage); m_splashScreen.showMessage(QObject::tr("Creating Test Item Page..."), Qt::AlignLeft | Qt::AlignTop, Qt::red); m_pTestItemPage = new TestItemPage(m_uiRatio); m_pTestItemPage->setFixedSize(width, height); ui.stackedWidget->addWidget(m_pTestItemPage); if (APP_NORMAL == LAppParam::GetStartMode()) ui.stackedWidget->setCurrentWidget(m_pHardwareInforPage); else if (APP_RESTARTAGING == LAppParam::GetStartMode()) ui.stackedWidget->setCurrentWidget(m_pTestItemPage); else ui.stackedWidget->setCurrentWidget(m_pTestItemPage); }