Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

Open a link in new dialog when left mouse or double clicked from a webengine view.?



  • i am a new to qt and i am in in issue i am unable to overcome it kindly help me.

    my work is like this for now. i have mainwindow.cpp and mainwindow.ui which loads the website.
    there are links in the website loaded i want to left mouse click it or double click the links present in the site but it should open a new dialog.ui with a webengineview and display the full story or the article clicked and also the previous view in mainwindow.ui should not load the url it should still be in same page or the website that was before the click so user can close the new dialog and comeback and select another link. currently when i click or double click it loads in same ui.

    please tell how i could do this.

    Thank you

    can you tell me how shall i proceed


  • Lifetime Qt Champion

    @nammi98 Do you use QML or C++ widgets?


  • Lifetime Qt Champion

    @nammi98 Maybe this could help:
    "If you want to provide support for web sites that allow the user to open new windows, such as pop-up windows, you can subclass QWebEngineView and reimplement the createWindow() function."
    From https://doc.qt.io/qt-5/qwebengineview.html#createWindow



  • @jsulm i am using c++



  • @jsulm i check this solution and get back.



  • @jsulm has already given the right answer.

    In case anyone arrives at this page and has a similar question but using QML, here is an example of handing the signal in QML:

      WebEngineView {
        id: thisWeb
    
        anchors.fill: parent
        url: dlViewModel.targetUrl
    
        onNewViewRequested: function (request) {
          // Any user can trigger newViewRequested by simply holding the CTRL key while clicking any hyperlink.
          // This forces any attempt at opening a new browser "tab" to open in this one instead:
          // (tested using qt 5.15 on Linux)
          // (refer to: https://doc.qt.io/qt-5/qml-qtwebengine-webengineview.html#newViewRequested-signal)
          request.openIn(thisWeb)
        }
      }
    

    The following is also a good resource:

    ^^ That example uses C++, so it is relevant to @nammi98



  • create window is not working @jsulm



  • class WebPage : public QWebEnginePage
    {
    Q_OBJECT

    public:
    explicit WebPage(QWebEngineProfile *profile, QWidget *parent = 0);
    ~WebPage();
    bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame);

    signals:
    void linkClicked(const QUrl &url);

    protected:
    QWebEnginePage* createWindow(WebWindowType type);

    private:

    Mainwindow* openUrlWebPage;
    };

    i creaed sub class like this but when ui in maindow i am not able to define why?


  • Lifetime Qt Champion

    @nammi98 said in Open a link in new dialog when left mouse or double clicked from a webengine view.?:

    i creaed sub class like this but when ui in maindow i am not able to define why?

    I'm not sure I understand



  • @jsulm in my mainwindow i am using GUI but i am not understanding how i can use create window reimplementation in gui application which opens user entered url in webengine view and how to navigate the links in the view to new dialog ui.



  • @nammi98 here is where you can find the source code (and *.pro file) for compiling the simplebrowser example that I linked to yesterday:

    https://github.com/qt/qtwebengine/tree/387fb9377d616/examples/webenginewidgets/simplebrowser

    ^^ that link is for using Qt 5.15.0, which may or may not be the version you are targeting. (Using the git history of the qt/qtwebengine repository you can roll back to whichever point in time matches your Qt framework version.)

    I recommend you try to build that example, and it will demonstrate to you the intended basic usage of all the webengine classes you are interested in.

    Here is the line of code in the sample project that overrides createWindow per the suggestion of @jsulm :

    https://github.com/qt/qtwebengine/blob/387fb9377d61683bcd0f59a637afffdd9a16912c/examples/webenginewidgets/simplebrowser/webview.h#L73

    I have not compiled this example myself, but I regularly compile other Qt examples when I need to "jump start" my thinking and my coding on some new Qt-based application that I am trying to write.

    Having only used webengine via QML thus var, I also don't have direct expertise in using it the way you intend to (with C++). However, I do believe that looking at the simplebrowser example will help.

    Something I just noticed that is creating confusion: both these classes have createWindow:

    I'm not sure what the significance of that is, but it certainly seems worth noting!



  • i have completed the work due to all the help given here thank you.
    now i want to build it as single standalone .exe file in release i did windeplyqt but it is creating multiple .dll and platforms and plugns is there any way for all this to be included in the .exe not seperate files.

    i checked static build its way complicated all i need is to build mywebengine project into a .exe file for deployment.



  • I haven't worked in Windows in several years, and I have not used windeployqt.

    Hopefully someone with more Windows/windeployqt expertise can respond. You might want to open a new forum thread with a windeployqt-related title to get the attention of the relevant people.

    You say that windeployqt ends up creating a situation with multiple DLLs and the platform plugins and so forth. My question to you would be: if you zip that into one folder, then download the folder on another windows machine, can you unzip it and everything runs? If so, I'd call that success. The last time I did any work on windows, it was common in my work to encounter apps that "installed" just like that.


Log in to reply