i have a simple app containing 3 classes:
- MainWindow
- Webpage
- Webview
The Mainwindow is a simple QT-Form.
WebView is derived from QWebView because i want to create a new window if a user clicks on a button with javascript. The script looks like this:
onclick="window.open('somefile.htm','NewWindow','width=450,height=750')"
onclick="window.open('somefile.htm','NewWindow','width=450,height=750')"
To copy to clipboard, switch view to plain text mode
Without that, a click on that button does nothing...
The Webview-Class has the following createWindow-Function(opens an empty Webview):
QWebView* Webview::createWindow(QWebPage::WebWindowType type)
{
switch(type)
{
case QWebPage::WebBrowserWindow: // The window is a regular web browser window
QMessageBox::information(NULL,
"Type",
"WebBrowserWindow:");
break;
case QWebPage::WebModalDialog: // The window acts as modal dialog.
QMessageBox::information(NULL,
"Type",
"WebModalDialog");
break;
default:
break;
}
return new QWebView(NULL);
}
QWebView* Webview::createWindow(QWebPage::WebWindowType type)
{
switch(type)
{
case QWebPage::WebBrowserWindow: // The window is a regular web browser window
QMessageBox::information(NULL, "Type", "WebBrowserWindow:");
break;
case QWebPage::WebModalDialog: // The window acts as modal dialog.
QMessageBox::information(NULL, "Type", "WebModalDialog");
break;
default:
break;
}
return new QWebView(NULL);
}
To copy to clipboard, switch view to plain text mode
In my MainWindow i created my QWebView and QWebPage, placed it on the form and load the html content with the buttons via load(). Works so far.
webview = new Webview(ui->centralWidget);
webpage = new Webpage(this);
webview->setPage(webpage);
webview
->load
(QUrl("file:///c:/Users/flammig-to/Documents/QTWebview/login.html"));
webview->show();
webview = new Webview(ui->centralWidget);
webpage = new Webpage(this);
webview->setPage(webpage);
webview->load(QUrl("file:///c:/Users/flammig-to/Documents/QTWebview/login.html"));
webview->show();
To copy to clipboard, switch view to plain text mode
Finally my acceptNavigationRequest-Methos in my webpage-class (which is derived from QWebpage):
bool Webpage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type)
{
return QWebPage::acceptNavigationRequest(frame,request,type);
}
bool Webpage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type)
{
return QWebPage::acceptNavigationRequest(frame,request,type);
}
To copy to clipboard, switch view to plain text mode
My problem is:
acceptNavigationRequest is only called at load-Time - but not when i click on the button of my html-page. The NavigationType is QWebPage::NavigationTypeOther. If i click on the button with my onclick-handler a new (of course empty) windows opens.
Maybe someone can help me..
Smudo
oh... i forgot:
i use QT 4.6.1 on XP and Win7
Bookmarks