Results 1 to 5 of 5

Thread: Convert html links in widget actions

  1. #1
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Convert html links in widget actions

    Hi,
    as in the title, is it possible clicking a link in a QWebView and perform an action in qt? I have attached an image to explain what I mean; in "Tab 1" there is a qwebview with three links; now when cliking on one of them should be activated the corresponding Tab.

    Thanks
    Attached Images Attached Images
    Giuseppe CalÃ

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Convert html links in widget actions

    Use the signal QWebView::linkClicked() and react on it. E.g.: href="#myAction::doOpenTab2".

  3. #3
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Convert html links in widget actions

    First of all thanks for the quick reply; I'm trying to follow your suggestion but I don't know what should be '#myAction::'

    Edit:

    I've added this line:

    Qt Code:
    1. connect(ui->webView,SIGNAL(linkClicked(QUrl)), this, SLOT(openTab(QUrl)));
    To copy to clipboard, switch view to plain text mode 

    but seems that linkClicked() signal isn't emitted; I've tryed with this simple code:

    Qt Code:
    1. void MainWindow::openTab(QUrl u)
    2. {
    3. qDebug() << "you have clicked a link...";
    4. }
    To copy to clipboard, switch view to plain text mode 

    but no output in terminal.
    Last edited by jiveaxe; 15th November 2009 at 19:09.
    Giuseppe CalÃ

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Convert html links in widget actions

    Quote Originally Posted by jiveaxe View Post
    I'm trying to follow your suggestion but I don't know what should be '#myAction::'
    It's just a magic string you could parse in your slot and react on its value.
    For your other problem look that you have the right linkDelegationPolicy.

  5. The following user says thank you to Lykurg for this useful post:

    jiveaxe (16th November 2009)

  6. #5
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Convert html links in widget actions

    Quote Originally Posted by Lykurg View Post
    For your other problem look that you have the right linkDelegationPolicy.
    Perhaps I'm wrong but it is not possible to set linkDelegationPolicy for a QWebView; it seems a property of QWebPage, that isn't a widget.

    EDIT:

    I've added the following lines:

    Qt Code:
    1. page = new QWebPage;
    2. page->setView(ui->webView);
    3. page->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
    To copy to clipboard, switch view to plain text mode 

    now, both QWebView and QWebPage have setHtml() and linkClicked(): what is the right combination to use? I've tryed using setHtml() of QWebView and linkClicked() of QWebView the first time and of QWebPage the second but with no success.

    EDIT 2:

    Forget my last edit, have found QWebView::page() so adding this line:

    Qt Code:
    1. ui->webView->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );
    To copy to clipboard, switch view to plain text mode 

    now it works; two final questions:

    1) the url returned with linkClicked() contains 'about:blank...': is it possible avoid it?
    2) now the function that parses the clicked url is a sequence of if...else; can you suggest me a more elegant way?

    Very thanks
    Last edited by jiveaxe; 16th November 2009 at 13:05.
    Giuseppe CalÃ

Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  2. Is there a widget fully support html in QT4?
    By hashb in forum Qt Programming
    Replies: 2
    Last Post: 15th October 2009, 02:05
  3. Is there a widget for display HTML files?
    By JeffJones in forum Newbie
    Replies: 6
    Last Post: 24th May 2007, 19:29
  4. Widget to display an HTML page ?
    By probine in forum Qt Tools
    Replies: 3
    Last Post: 11th October 2006, 18:55
  5. Qt html widget
    By js67257 in forum Qt Programming
    Replies: 1
    Last Post: 6th September 2006, 14:34

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.