firemail
标题:
WebEngineView
[打印本页]
作者:
Qter
时间:
2023-9-18 18:32
标题:
WebEngineView
void WebEngineView::setHtml(const QString& html, const QUrl& baseUrl)
{
//m_widgetSize = this->size();//QWebEnginPage的setHtml存在一个问题,如果加载的html内容较少,则窗口大小会固定为一个很小的尺寸,影响了客户端布局,所以在sethtml之前先把原尺寸保存,之后再设置回来
auto s = html.size();
QString tmpHtml = html;
//tmpHtml.replace("src=\"//", "src=\"https://"); // 保存本地html后 图片资源会从本地加载 造成卡顿 替换为网络加载
//if (s > 200000)
if (true)//程序运行时如果调了load接口和setHtml接口,则eventfileter会失效,所以只能统一调load接口避开这个坑
{
QString tmpPath(MakeUniqueDir(AppDataDir("mailreader")));
QString mailHtmlPath = tmpPath + "mailreader.html";
QFile f(mailHtmlPath);
QTextStream out(&f);
bool openRes = f.open(QIODevice::WriteOnly);
if (openRes)
{
auto writeRes = f.write(tmpHtml.toUtf8());
if (writeRes == -1)
{
qCritical() << "WRITE TEMP MAIL CONTENT FILE FAILD," << "FILE PATH IS: " << mailHtmlPath;
}
else
{
f.close();
QUrl url = QUrl::fromLocalFile(mailHtmlPath);
load(url);
//m_qWebEngineView->setHtml(html, baseUrl);
}
}
else
qCritical() << "OPEN TEMP MAIL CONTENT FILE FAILD," << "FILE PATH IS: " << mailHtmlPath;
}
}
欢迎光临 firemail (http://firemail.wang:8088/)
Powered by Discuz! X3