QWebView allow pop-ups?

北城以北 提交于 2019-12-13 02:18:38

问题


In my project, I have a QWebView that loads a page that opens a pop-up window. But the window won't open. I looked into the createWindow function but I have no clue how to subclass a widget. These are some settings I put onto the webView:

QWebSettings *settings = ui->webView_2->settings();
settings->setAttribute(QWebSettings::JavascriptEnabled, true);
settings->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);

What is the easiest way to allow my webView to allow pop-up windows?

Thanks for your time :)


回答1:


You need to reimplement QWebView's createWindow method. The QWebView returned will be set to the required URL automatically.

For example:

QWebView* WebView::createWindow(QWebPage::WebWindowType type)
{
    // WindowDialog is just a simple QDialog with a QWebView
    WindowDialog* dlg = new WindowDialog(this);
    dlg->show();

    // A method to retrieve a pointer to the QWebView of the dialog is needed
    return dlg->webView();
}

Keep in mind that cookies do not share between the two QWebViews, so you also need to implement your own cookie manager. One way to do it would be to inherit QNetworkCookieJar, and keep a static "global" instance.



来源:https://stackoverflow.com/questions/19615954/qwebview-allow-pop-ups

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!