Results 1 to 2 of 2

Thread: Combining QWebView, QWebPage and createWindow (acceptNavigationRequest)

  1. #1
    Join Date
    Mar 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Combining QWebView, QWebPage and createWindow (acceptNavigationRequest)

    i have a simple app containing 3 classes:

    1. MainWindow
    2. Webpage
    3. 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:

    Qt Code:
    1. 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):

    Qt Code:
    1. QWebView* Webview::createWindow(QWebPage::WebWindowType type)
    2. {
    3. switch(type)
    4. {
    5. case QWebPage::WebBrowserWindow: // The window is a regular web browser window
    6. QMessageBox::information(NULL, "Type", "WebBrowserWindow:");
    7. break;
    8. case QWebPage::WebModalDialog: // The window acts as modal dialog.
    9. QMessageBox::information(NULL, "Type", "WebModalDialog");
    10. break;
    11. default:
    12. break;
    13. }
    14.  
    15. return new QWebView(NULL);
    16. }
    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.

    Qt Code:
    1. webview = new Webview(ui->centralWidget);
    2. webpage = new Webpage(this);
    3. webview->setPage(webpage);
    4. webview->load(QUrl("file:///c:/Users/flammig-to/Documents/QTWebview/login.html"));
    5. 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):

    Qt Code:
    1. bool Webpage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type)
    2. {
    3. return QWebPage::acceptNavigationRequest(frame,request,type);
    4. }
    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
    Last edited by smudo; 2nd March 2010 at 12:41.

  2. #2
    Join Date
    Mar 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Combining QWebView, QWebPage and createWindow (acceptNavigationRequest)

    ok, i found out: acceptNavigationRequest only gets fired when i hit - for example - the submit-button but not by simply hit a button.
    So, a last question: how can i access the url (request) when QWebview calls createWindow?

Similar Threads

  1. Replies: 2
    Last Post: 16th June 2010, 15:42
  2. Get images from a QWebView or QWebPage
    By redneon in forum Qt Programming
    Replies: 6
    Last Post: 21st January 2010, 09:03
  3. combining wheel events
    By mcarter in forum Qt Programming
    Replies: 1
    Last Post: 13th January 2010, 05:59
  4. Widgets combining CSS and SVG
    By yop in forum Qt Programming
    Replies: 3
    Last Post: 15th October 2008, 10:02
  5. Combining different widgets
    By ShaChris23 in forum Newbie
    Replies: 3
    Last Post: 1st May 2007, 02:23

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.