Qt WebEngine 特征

Qt WebEngine 支持下列特征:

音频和视频编解码器

Qt WebEngine supports the MPEG-4 Part 14 (MP4) file format only if the required proprietary audio and video codecs, such as H.264 and MPEG layer-3 (MP3), have been enabled. Proprietary codecs can be enabled by passing the following option when configuring Qt:

-proprietary-codecs
					

警告: 当分发专有编解码器库时,它们必须获得许可。

FFmpeg 是录制、转换及流化音频 视频的跨平台解决方案。可以将其配置为与多个编解码器一起使用,但带编解码器库分发时会引发许可问题。对于某些编解码器,开源实现,譬如 OpenH264 ,是可用的。

Chromium DevTools

Chromium DevTools 提供审查 调试任何 Web 内容的布局和性能问题的能力。

可以测试此特征通过启动 Qt WebEngine 应用程序采用命令行选项 --remote-debugging-port=[your-port] 或通过设置环境变量 QTWEBENGINE_REMOTE_DEBUGGING ,然后使用基于 Chromium 的浏览器 (譬如 Demo Browser or 纳米浏览器 ) 去连接到 http://localhost:[your-port] .

更多信息,见 Qt WebEngine 调试和剖分析 .

拖放

Qt WebEngine 支持 HTML5 拖放。

可以通过打开 HTML5 拖放演示来测试此特征,譬如 HTML5 演示 - 拖放 , HTML5 演示 - 简单拖放 ,或 HTML5 演示 - 拖放,自动上传 , in Demo Browser or 纳米浏览器 .

把文件拖拽到浏览器中实际上不属于 HTML5,但它是受支持的。可以测试它通过打开 HTML5 演示 - 文件 API .

该特征支持在 Qt 5.7.0 添加。

Fullscreen

Qt WebEngine supports viewing web content in fullscreen mode. For more information, see WebEngineSettings.fullscreenSupportEnabled , WebEngineView.fullScreenRequested , QWebEngineSettings::FullScreenSupportEnabled ,和 QWebEnginePage::fullScreenRequested .

This feature can be tested by playing a video from YouTube in Demo Browser or 纳米浏览器 , and clicking the full screen icon to go into fullscreen mode.

该特征支持在 Qt 5.6.0 添加。

HTML5 DRM

Qt WebEngine 支持查看 DRM (数字版权管理) 保护视频若 Widevine DRM plugin has been installed.

The video format most commonly used by DRM services, H.264, requires proprietary audio and video codecs. For more information about enabling the codecs, see 音频和视频编解码器 .

This feature can be tested by playing a video in Demo Browser or 纳米浏览器 from castLabs , Swank Motion Pictures, Inc. ,或 Shaka Player .

该特征支持在 Qt 5.7.0 添加。

HTML5 地理位置

Qt WebEngine supports JavaScript Geolocation API with Qt Location as a backend. The application has to explicitly allow the feature by using QWebEnginePage::Geolocation or WebEngineView.Feature .

This feature can be tested if Qt Location has been built before Qt WebEngine. The http://html5demos.com/geo page can be opened in the Demo Browser and allowed to find the current position of the user. Note that on Windows an external GPS receiver must be connected to the application. For more information, see Qt Positioning .

该特征支持在 Qt 5.5.0 添加。

HTTP/2 协议

Qt WebEngine supports the Chromium implementation of the HTTP/2 协议。

This feature can be tested by opening an HTTP/2 demo, such as the Akamai HTTP/2 Demo , in 简单浏览器 or 纳米浏览器 .

本机对话框

A web page might request dialogs for the following functions:

  • Entering user credentials for HTTP and proxy authentication
  • Displaying JavaScript alerts, confirmation dialogs, and prompts
  • Picking colors
  • Selecting files
  • Displaying form validation messages

Qt WebEngine provides standard dialogs for these functions. In widget-based applications, the standard dialogs are based on QDialog , whereas in Qt Quick applications, they can be based either on Qt Quick Controls 1 or Qt Quick Controls 2 (since Qt 5.8). The latter are used only on eglfs 平台。

To explicitly force either dialogs based on Qt Quick Controls 1 or Qt Quick Controls 2, set the QTWEBENGINE_DIALOG_SET environment variable to either QtQuickControls1 or QtQuickControls2 .

Qt WebEngine Widgets dialogs can be customized by reimplementing the QWebEnginePage::chooseFiles (), QWebEnginePage::javaScriptAlert (), QWebEnginePage::javaScriptConfirm (),和 QWebEnginePage::javaScriptPrompt () 函数。

Since Qt 5.8, Qt Quick dialogs can be customized by connecting to the WebEngineView::authenticationDialogRequested (), WebEngineView::javaScriptDialogRequested (), WebEngineView::colorDialogRequested (), WebEngineView::fileDialogRequested (),和 WebEngineView::formValidationMessageRequested () signals. For an example, see WebEngine Qt Quick 自定义对话框范例 .

Pepper 插件 API

Qt WebEngine supports loading Pepper Plugin API (PPAPI) plugins if WebEngineSettings::pluginsEnabled or QWebEngineSettings::PluginsEnabled 有设置。

Except for the Adobe Flash Player plugin, the plugins must be loaded manually using the Chromium command line syntax with the --register-pepper-plugins argument. The argument value is a list of entries, separated by commas, that contain the file path and one or several MIME types, separated by semicolons:

<file-path-plugin1>;<mime-type-plugin1>,<file-path-plugin2>;<mime-type1-plugin2>;<mime-type2-plugin2>
					

例如:

--register-pepper-plugins="libppapi_example.so;application/x-ppapi-example"
					

The MIME type is important because it determines which embeds the plugin is used for.

该特征支持在 Qt 5.6.0 添加。

Pepper Flash Player 插件支持

The Pepper Flash player plugin can be loaded automatically if it is installed in one of the following locations, depending on the platform:

  • Windows
    C:\Windows\SysWOW64\Macromed\Flash\pepflashplayer*.dll
    C:\Windows\System32\Macromed\Flash\pepflashplayer*.dll
    							
  • OS X
    /Library/Internet Plug-Ins/PepperFlashPlayer/PepperFlashPlayer.plugin
    							
  • Linux
    /usr/lib/pepperflashplugin-nonfree/libpepflashplayer.so
    /usr/lib/adobe-flashplugin/libpepflashplayer.so
    /usr/lib/PepperFlash/libpepflashplayer.so
    /usr/lib64/chromium/PepperFlash/libpepflashplayer.so
    							

You can also load the Pepper Flash player from a specific location by using command line arguments:

--ppapi-flash-path=./libpepflashplayer.so
					

By default, the Flash version is set to 11.2.999.999 。可以使用 ppapi-flash-version= argument to set another Flash version in the format major.minor.build.revision :

--ppapi-flash-version=16.0.0.235
					

This feature can be tested in Demo Browser or 纳米浏览器 if the Adobe Flash PPAPI plugin is installed and plugins are enabled in the browser. To test the feature, the https://helpx.adobe.com/flash-player.html page can be opened in the browser.

Qt WebEngine 支持把网页打印成 PDF 文件。更多信息,见 QWebEnginePage::printToPdf () 和 WebEngineView.printToPdf .

This feature can be tested in Demo Browser by selecting File > 打印到 PDF .

该特征支持在 Qt 5.7.0 添加。

拼写检查器

Qt WebEngine supports integrating spellchecking support into HTML forms to enable users to submit spellchecked messages. When the user clicks on an underlined misspelled word, the default context menu displays up to four suggestions. Selecting one will replace the misspelled word.

To be able to check the spelling, the spellchecker needs dictionaries. It supports dictionaries from the Hunspell project , but they have to be compiled into a special binary format. A Hunspell dictionary consists of two files:

  • A .dic file that is a dictionary containing words for the language
  • An .aff file that defines the meaning of special flags in the dictionary

These two files can be converted into the bdic format by using the qwebengine_convert_dict tool that is shipped together with Qt. When the Qt WebEngine spellchecker initializes, it will try to load the bdict dictionaries and to check them for consistency. First, it searches qtwebengine_dictionaries directories relative to the executable, then it will look in QT_INSTALL_PREFIX/qtwebengine_dictionaries .

Spellchecking is disabled by default and can be enabled per profile by using the QWebEngineProfile::setSpellCheckEnabled () method in widget-based applications and the WebEngineProfile.spellCheckEnabled property in Qt Quick applications.

The current language used for spellchecking is defined per profile, and can be set using the QWebEngineProfile::setSpellCheckLanguages () method or the WebEngineProfile.spellCheckLanguages 特性。

可以测试此特征通过构建和运行 拼写检查器范例 .

该特征支持在 Qt 5.8.0 添加。

触摸

Qt WebEngine 支持导航和交互网页的触摸设备。

Applications can prohibit the use of touch events in the following ways:

  • Passing the flag --touch-events=disabled on the command line will disable touch event support in JavaScript API (meaning ontouchstart and related handlers will not be present in the document.window object). Touch events will still be delivered to web pages.
  • Installing an event filter object using QObject::installEventFilter on the WebEngine view focus proxy object, and filtering out all touch events.

查看源

Qt WebEngine 支持查看网页的 HTML 源。

This feature can be used from custom menus or assigned to custom events. For more information, see WebEngineView::WebAction ,和 QWebEnginePage::WebAction .

This feature can be tested by opening a web page in 简单浏览器 or 纳米浏览器 , and then selecting Page Source in the context menu. The Page Source context menu entry opens the source view in a new tab.

For opening the source view in the current tab, URLs with view-source URI scheme are also supported. For example, you can type the following URL to the URL bar to view the HTML source of the qt.io web page:

view-source:https://www.qt.io/
					

Auto-completion of incomplete URLs with view-source URI scheme makes the usage of this feature more comfortable. For example, the following incomplete URL also loads the source view of the qt.io web page:

view-source:qt.io
					

该特征支持在 Qt 5.8.0 添加。

WebRTC

WebRTC 凭借简单 API 为浏览器提供 RTC (实时通信) 能力。更多信息,见 WebEngineView.Feature and QWebEnginePage::Feature .

This feature can be tested by setting up a webcam or microphone and then opening https://test.webrtc.org/ in 简单浏览器 or 纳米浏览器 .