将页面加载到QWebView时重叠 [英] Overlay while loading page into QWebView
问题描述
假设我们有一个准系统QWebView:
Let's say we have a barebones QWebView:
#include <QApplication>
#include <QWebView>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QWebView view;
view.show();
view.setUrl(QUrl("http://google.com"));
return app.exec();
}
如何显示图形叠加层,最好是全屏的透明度和最小的动画像定时器/ beachball /等)从页面开始加载,直到它完成?在 QWebView 中更改网址时也应触发。
How can I display a graphic overlay, preferably fullscreen with transparency and minimal animation (like timer/beachball/etc.) from when the page starts loading till it's finished? Should also be triggered when url changes from within the QWebView.
推荐答案
您可以使用 LoadingOverlay stackoverflow.com/questions/19383427/blur-effect-over-a-qwidget-in-qt/19386886#19386886\">此答案在任何 QWidget $ c上绘制叠加层$ c>。在你的情况下,当信号
loadStarted
被触发并隐藏时,在 QWebView
信号 loadFinished
被触发。
You can use the LoadingOverlay
class provided in this answer to draw an overlay over any QWidget
. In your case, show the overlay on top of the QWebView
when the signal loadStarted
is triggered and hide it, when the signal loadFinished
is triggered.
下面的代码让你开始。我将来自链接答案的代码放入 overlay.h
,处理覆盖的显示/隐藏的 QWebView
的子类是 webview.h
:
The following code should get you started. I put the code from the linked answer into overlay.h
, the subclass of QWebView
which handles the showing/hiding of the overlay is in webview.h
:
webview.h
#include "overlay.h"
#include <QWebView>
class WebView : public QWebView
{
Q_OBJECT
public:
WebView(QWidget * parent) : QWebView(parent)
{
overlay = new LoadingOverlay(parent);
connect(this,SIGNAL(loadFinished(bool)),this,SLOT(hideOverlay()));
connect(this,SIGNAL(loadStarted()),this,SLOT(showOverlay()));
}
~WebView()
{
}
public slots:
void showOverlay()
{
overlay->show();
}
void hideOverlay()
{
overlay->hide();
}
private:
LoadingOverlay* overlay;
};
main.cpp
#include <QApplication>
#include "overlay.h"
#include "webview.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ContainerWidget base;
Webview w(&base);
base.show();
w.load(QUrl("http://google.com"));
return a.exec();
}
这篇关于将页面加载到QWebView时重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!