实现QT6启动器,QT版本有qt5升级到qt6

This commit is contained in:
lixiaoyuan
2025-09-10 20:10:51 +08:00
parent 3d03bbe9b5
commit e822d57b67
188 changed files with 1376 additions and 219 deletions

View File

@@ -4,7 +4,10 @@
#include <QCoreApplication>
#include <QLabel>
#include <QThread>
#include <QWebEngineSettings>
#include <QWebEngineProfile>
#include <QAction>
#include <QToolBar>
void MySplash(MainWeb* mainWin)
{
@@ -28,6 +31,7 @@ void MySplash(MainWeb* mainWin)
{
splash.showMessage(QString("Loading... %1 ms").arg(i), Qt::AlignBottom | Qt::AlignRight, Qt::black);
labelProgress.setGeometry(100, 480, i*2*0.8, 20);
QCoreApplication::processEvents();
QThread::msleep(10);
}
@@ -39,19 +43,63 @@ MainWeb::MainWeb()
{
this->setWindowTitle("光储充站监控与运营管理平台");
this->setGeometry(0, 0, 1920, 1080);
this->hide();
// 在加载页面之前清除缓存
//QWebEngineProfile::defaultProfile()->clearHttpCache();
//QWebEngineSettings* settings = webView.settings();
//settings->setAttribute(QWebEngineSettings::JavascriptEnabled, true);
//settings->setAttribute(QWebEngineSettings::LocalStorageEnabled, true);
//settings->setAttribute(QWebEngineSettings::AllowRunningInsecureContent, true); // 解决http资源加载问题
//settings->setAttribute(QWebEngineSettings::PluginsEnabled, true);
webView.setGeometry(0, 0, 1920, 1080);
// 默认设置透明, 解决加载时的白屏闪烁
webView.page()->setBackgroundColor(Qt::transparent);
webView.setContextMenuPolicy(Qt::NoContextMenu);
//webView.page()->setBackgroundColor(Qt::transparent);
//webView.setContextMenuPolicy(Qt::NoContextMenu);
webView.load(QUrl(Config::option.webSrvUrl.c_str()));
//webView.load(QUrl("file:///assets/html/main.html"));
//connect(wWebView.get(), &QWebEngineView::loadFinished, this, &MyWidget::slotLoadFinished);
//std::string htmlContent = "HelloWorld";
//webView->setHtml(htmlContent.c_str(), QUrl("file:///assets/html/"));
webView.show();
this->setCentralWidget(&webView);
MySplash(this);
this->show();
//===动态程序启动画面===
splash = std::make_shared<QSplashScreen>(QPixmap("./assets/ui/splash.png"));
QCoreApplication::processEvents();
label1.setParent(splash.get());
label1.setStyleSheet("background-color: gray");
label1.setGeometry(100, 480, 800, 20);
labelProgress.setParent(splash.get());
labelProgress.setStyleSheet("background-color: rgb(29, 54, 102)");
labelProgress.setGeometry(10, 10, 0, 20);
splash->show();
label1.show();
labelProgress.show();
QObject::connect(&webView, &QWebEngineView::loadFinished, [=](bool ok)
{
if (ok)
{
int i = 0;
while ((++i)<100)
{
splash->showMessage(QString("Loading... %1 ms").arg(i), Qt::AlignBottom | Qt::AlignRight, Qt::black);
labelProgress.setGeometry(100, 480, i*10*0.8, 20);
QCoreApplication::processEvents();
QThread::msleep(20);
}
splash->finish(this);//程序启动画面结束
this->show();
}
else
{
qDebug() << "页面加载失败!";
// 这里可以执行加载失败后的处理
}
});
//this->show();
}