WebEngine Widgets 最小範例

WebEngine Widgets 最小範例 演示如何使用 QWebEngineView to render a web page. It shows the minimum amount of code needed to load and display an HTML page, and can be used as a basis for further experimentation.

運行範例

要運行範例從 Qt Creator ,打開 歡迎 模式,然後選擇範例從 範例 。更多信息,拜訪 構建和運行範例 .

代碼

main function we first set the Qt::AA_EnableHighDpiScaling . This lets the web view automatically scale on high-dpi displays.

Next, we instantiate a QApplication QWebEngineView . The URL to load is set by calling QWebEngineView::setUrl . The view widget is given a reasonable default size, and shown. Finally, QApplication::exec () launches the main event loop.

#include <QApplication>
#include <QWebEngineView>
int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QApplication app(argc, argv);
    QWebEngineView view;
    view.setUrl(QUrl(QStringLiteral("http://www.qt.io")));
    view.resize(1024, 750);
    view.show();
    return app.exec();
}
					
					

要求

The example requires a working internet connection to render the Qt Homepage . An optional system proxy should be picked up automatically. However, for proxies that require a username or password, you need to connect to QWebEnginePage::proxyAuthenticationRequired .

Qt WebEngine Widgets 使用 Qt Quick 場景圖形 去閤成頁麵。因此,需要 OpenGL 支持。

文件: