WIP (Qt)
1 manually trigger the QWebEnginePage::SavePage action========
QMenu *menu;
if (page()->contextMenuData().linkUrl().isValid()) {
menu = new QMenu(this);
menu->addAction(page()->action(QWebEnginePage::OpenLinkInThisWindow));
menu->addAction(page()->action(QWebEnginePage::OpenLinkInNewWindow));
menu->addAction(page()->action(QWebEnginePage::OpenLinkInNewTab));
menu->addAction(page()->action(QWebEnginePage::OpenLinkInNewBackgroundTab));
menu->addSeparator();
menu->addAction(page()->action(QWebEnginePage::DownloadLinkToDisk));
menu->addAction(page()->action(QWebEnginePage::CopyLinkToClipboard));
} else {
menu = page()->createStandardContextMenu();
}
if (page()->contextMenuData().selectedText().isEmpty())
menu->addAction(page()->action(QWebEnginePage::SavePage));
connect(menu, &QMenu::aboutToHide, menu, &QObject::deleteLater);
menu->popup(event->globalPos());
2. ========
void TabWidget::downloadRequested(QWebEngineDownloadItem *download)
{
if (download->savePageFormat() != QWebEngineDownloadItem::UnknownSaveFormat) {
SavePageDialog dlg(this, download->savePageFormat(), download->path());
if (dlg.exec() != SavePageDialog::Accepted)
return;
download->setSavePageFormat(dlg.pageFormat());
download->setPath(dlg.filePath());
}
BrowserApplication::downloadManager()->download(download);
download->accept();
}
=====
http://stackoverflow.com/questions/38812787/how-to-handle-downloads-in-qwebengine
======
http://doc.qt.io/qt-5/qwebengineprofile.html#downloadRequested
======
http://doc.qt.io/qt-5/qwebenginepage.html#save
No comments:
Post a Comment