[Solved] Catching click on links in WebView
Hi,
I want to catch click on links in WebView in QML. Right now there is no linkClicked signal in WebView. What is the ideal solution in this case ? Should I develop my own plugin which binds QWebView and generates linkClicked signals ?
6 replies
Ok I found another workaround using QGraphicsProxyWidget :
MyWebView.cpp
- #include "rswebview.h"
- #include <QWebFrame>
- #include <QDebug>
- {
- // ... connect signals that you need ...
- setWidget(webview);
- }
- {
- webview->load(url);
- }
- //Implement methods that you need
myWebView.h
- #include <QGraphicsProxyWidget>
- #include <QWebView>
- {
- Q_OBJECT
- //... add properties that you need
- public:
- //... methods that you need ...
- signals:
- void loadStarted();
- void loadFailed();
- void loadProgress(int progress);
- //... add signals that you need ...
- void loadFinished();
- public slots:
- void stop();
- void back();
- //... add slots that you need ...
- void reload();
- private:
- };
in your main.cpp
- qmlRegisterType<MyWebView>("mylib", 1, 0, "MyWebView");
in QML :
- import mylib 1.0
- MyWebView
- {
- height: contentSize.height
- // ... use as before
- }
The only problem I get is to assign the right height to the webview.
Because even if you place it in a Flickable and set anchors to fill parent, it wont expend.
The solution is to bind the height to webview->page()->mainFrame()->contentsSize().height
You must log in to post a reply. Not a member yet? Register here!




