Menu

Main Menu
Talk Get Daily Search

Member's Online

    User Name
    Password

    Open with Webview from onLinkActivated(link)

    Reply
    Markkyboy | # 1 | 2017-11-12, 21:34 | Report

    I have a page which deals with displaying messages produced from an external source, so far, all is working well.

    Currently, when a message has been generated by the external source, the message may contain a link to take you to the operators website for further information, by clicking the link, sailfish-browser is opened, but I would actually prefer WebView to handle the page, but how do I make this work, here's my code so far;


    StationMessages.qml

    Code:
                Label {
                    id: message
                    text: model.message
                    width: parent.width
                    wrapMode: Text.WordWrap
                    textFormat: Text.RichText
                    x: Theme.horizontalPageMargin + Theme.paddingMedium
                    anchors {
                        top: parent.top
                        topMargin: Theme.paddingLarge
                        horizontalCenter: parent.hoizontalCenter
                    }
                    onLinkActivated: Qt.openUrlExternally(link)
    The Webview page set up, but how to link the two pages, for some reason, I cannot wrap my head round this or find any examples;


    MessageView.qml

    Code:
    Page {
        SilicaWebView {
            anchors.fill: parent
            header: PageHeader { title: "Message view" }
            url: ???
        }
    }

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following User Says Thank You to Markkyboy For This Useful Post:
    juiceme

     
    coderus | # 2 | 2017-11-13, 08:00 | Report

    Read webcat/webpirate source code, it's not that trivial.

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 2 Users Say Thank You to coderus For This Useful Post:
    jakibaki, juiceme

     
    llelectronics | # 3 | 2017-11-13, 10:52 | Report

    It seems to me like you are searching for the pageStack feature to allow attaching a new page with the webview which should load the url for you.

    You can easily to this that way.

    StationMessages.qml
    Code:
    ...
    onLinkActivated: pageStack.push(Qt.resolvedUrl("MessageView.qml"), {"gotoUrl": link})
    MessageView.qml
    Code:
    Page {
        property string gotoUrl
        SilicaWebView {
            anchors.fill: parent
            header: PageHeader { title: "Message view" }
            url: gotoUrl
        }
    }
    Of course the MessageView.qml maybe needs some GUI elements aswell like a simple bar with back button or reload stop button. Thats something you can take a look at harbour-tidings. It has a simple and easy toolbar (in contrast to my Webcat browser which has a very complicated toolbar thingy): https://github.com/pycage/tidings/bl...bPage.qml#L106

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 5 Users Say Thank You to llelectronics For This Useful Post:
    imaginaryenemy, juiceme, maegon9y00, Markkyboy, suicidal_orange

     
    Markkyboy | # 4 | 2017-11-13, 11:21 | Report

    Originally Posted by llelectronics View Post
    It seems to me like you are searching for the pageStack feature to allow attaching a new page with the webview which should load the url for you.

    You can easily to this that way.

    StationMessages.qml
    Code:
    ...
    onLinkActivated: pageStack.push(Qt.resolvedUrl("MessageView.qml"), {"gotoUrl": link})
    MessageView.qml
    Code:
    Page {
        property string gotoUrl
        SilicaWebView {
            anchors.fill: parent
            header: PageHeader { title: "Message view" }
            url: gotoUrl
        }
    }
    Of course the MessageView.qml maybe needs some GUI elements aswell like a simple bar with back button or reload stop button. Thats something you can take a look at harbour-tidings. It has a simple and easy toolbar (in contrast to my Webcat browser which has a very complicated toolbar thingy): https://github.com/pycage/tidings/bl...bPage.qml#L106
    Thank you @llelectronics, that does the trick!....I had been playing with pageStack, I got the webview to open, but couldn't get it to populate with the page, because I was missing the simple 'gotoUrl' function you've shown me!, excellent!

    Thanks again,

    Regards,

    Mark

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 2 Users Say Thank You to Markkyboy For This Useful Post:
    imaginaryenemy, juiceme

     
vBulletin® Version 3.8.8
Normal Logout