QWebEngineSettings Class

The QWebEngineSettings class provides an object to store the settings used by QWebEnginePage. More...

Header: #include <QWebEngineSettings>
CMake: find_package(Qt6 REQUIRED COMPONENTS WebEngineCore)
target_link_libraries(mytarget PRIVATE Qt6::WebEngineCore)
qmake: QT += webenginecore

Public Types

enum FontFamily { StandardFont, FixedFont, SerifFont, SansSerifFont, CursiveFont, …, PictographFont }
enum FontSize { MinimumFontSize, MinimumLogicalFontSize, DefaultFontSize, DefaultFixedFontSize }
(since Qt 6.8) enum class ImageAnimationPolicy { Allow, AnimateOnce, Disallow }
(since Qt 5.11) enum UnknownUrlSchemePolicy { DisallowUnknownUrlSchemes, AllowUnknownUrlSchemesFromUserInteraction, AllowAllUnknownUrlSchemes }
enum WebAttribute { AutoLoadImages, JavascriptEnabled, JavascriptCanOpenWindows, JavascriptCanAccessClipboard, LinksIncludedInFocusChain, …, ForceDarkMode }

Public Functions

QString defaultTextEncoding() const
QString fontFamily(QWebEngineSettings::FontFamily which) const
int fontSize(QWebEngineSettings::FontSize type) const
(since Qt 6.8) QWebEngineSettings::ImageAnimationPolicy imageAnimationPolicy() const
void resetAttribute(QWebEngineSettings::WebAttribute attribute)
void resetFontFamily(QWebEngineSettings::FontFamily which)
void resetFontSize(QWebEngineSettings::FontSize type)
(since Qt 6.8) void resetImageAnimationPolicy()
(since Qt 5.11) void resetUnknownUrlSchemePolicy()
void setAttribute(QWebEngineSettings::WebAttribute attribute, bool on)
void setDefaultTextEncoding(const QString &encoding)
void setFontSize(QWebEngineSettings::FontSize type, int size)
(since Qt 6.8) void setImageAnimationPolicy(QWebEngineSettings::ImageAnimationPolicy policy)
(since Qt 5.11) void setUnknownUrlSchemePolicy(QWebEngineSettings::UnknownUrlSchemePolicy policy)
bool testAttribute(QWebEngineSettings::WebAttribute attribute) const
(since Qt 5.11) QWebEngineSettings::UnknownUrlSchemePolicy unknownUrlSchemePolicy() const

Detailed Description

QWebEngineSettings allows configuration of browser properties, such as font sizes and families, and generic attributes, such as JavaScript support. Individual attributes are set using the setAttribute() function. The WebAttribute enum further describes each attribute.

Each QWebEnginePage object has its own QWebEngineSettings object, which configures the settings for that page. If a setting is not configured for a web engine page, it is looked up in the settings of the profile the page belongs to.

See also QWebEnginePage::settings() and QWebEngineView::settings().

Member Type Documentation

enum QWebEngineSettings::FontFamily

This enum describes the generic font families defined by CSS 2. For more information see the CSS standard.

ConstantValueDescription
QWebEngineSettings::StandardFont0 
QWebEngineSettings::FixedFont1 
QWebEngineSettings::SerifFont2 
QWebEngineSettings::SansSerifFont3 
QWebEngineSettings::CursiveFont4 
QWebEngineSettings::FantasyFont5 
QWebEngineSettings::PictographFont6(added in Qt 5.7, deprecated Qt 6.4)

enum QWebEngineSettings::FontSize

This enum describes the font sizes configurable through QWebEngineSettings:

ConstantValueDescription
QWebEngineSettings::MinimumFontSize0The hard minimum font size.
QWebEngineSettings::MinimumLogicalFontSize1The minimum logical font size that is applied when zooming out.
QWebEngineSettings::DefaultFontSize2The default font size for regular text.
QWebEngineSettings::DefaultFixedFontSize3The default font size for fixed-pitch text.

[since Qt 6.8] enum class QWebEngineSettings::ImageAnimationPolicy

This enum describes how an image animation should be handled when the image frames are rendered for animation.

ConstantValueDescription
QWebEngineSettings::ImageAnimationPolicy::Allow1Allows image animation when the image frames are rendered.
QWebEngineSettings::ImageAnimationPolicy::AnimateOnce2Animate the image once when the image frames are rendered.
QWebEngineSettings::ImageAnimationPolicy::Disallow3Disallows image animation when the image frames are rendered.

This enum was introduced in Qt 6.8.

See also imageAnimationPolicy, setImageAnimationPolicy, and resetImageAnimationPolicy.

[since Qt 5.11] enum QWebEngineSettings::UnknownUrlSchemePolicy

This enum describes how navigation requests to URLs with unknown schemes are handled.

ConstantValueDescription
QWebEngineSettings::DisallowUnknownUrlSchemes1Disallows all navigation requests to URLs with unknown schemes.
QWebEngineSettings::AllowUnknownUrlSchemesFromUserInteraction2Allows navigation requests to URLs with unknown schemes that are issued from user-interaction (like a mouse-click), whereas other navigation requests (for example from JavaScript) are suppressed.
QWebEngineSettings::AllowAllUnknownUrlSchemes3Allows all navigation requests to URLs with unknown schemes.

This enum was introduced in Qt 5.11.

See also unknownUrlSchemePolicy, setUnknownUrlSchemePolicy, and resetUnknownUrlSchemePolicy.

enum QWebEngineSettings::WebAttribute

This enum type specifies settings for web pages:

ConstantValueDescription
QWebEngineSettings::AutoLoadImages0Automatically dowloads images for web pages. When this setting is disabled, images are loaded from the cache. Enabled by default.
QWebEngineSettings::JavascriptEnabled1Enables the running of JavaScript programs in the MainWorld. Enabled by default.
QWebEngineSettings::JavascriptCanOpenWindows2Allows JavaScript programs to open popup windows without user interaction. Enabled by default.
QWebEngineSettings::JavascriptCanAccessClipboard3Allows JavaScript programs to write (copy) sanitized content to the clipboard. A sanitized write is done with the write and writeText JavaScript Clipboard API calls and must be accompanied by user action. Unsanitized writes, and reading from the clipboard, are enabled by JavascriptCanPaste. Prior to Chromium version 81, this setting enabled all clipboard writes. Since unrestricted clipboard access is a potential security concern, it is recommended that applications leave this disabled and instead respond to ClipboardReadWrite feature permission requests. Disabled by default.
QWebEngineSettings::LinksIncludedInFocusChain4Includes hyperlinks in the keyboard focus chain. Enabled by default.
QWebEngineSettings::LocalStorageEnabled5Enables support for the HTML 5 local storage feature. Enabled by default.
QWebEngineSettings::LocalContentCanAccessRemoteUrls6Allows local origin documents to access remote resources that would normally be blocked. Disabled by default. Note DnsPrefetchEnabled below operates independently of this setting, and can if enabled, cause remote accesses from local content.
QWebEngineSettings::XSSAuditingEnabled7Obsolete and has no effect.
QWebEngineSettings::SpatialNavigationEnabled8Enables the Spatial Navigation feature, which means the ability to navigate between focusable elements, such as hyperlinks and form controls, on a web page by using the Left, Right, Up and Down arrow keys. For example, if a user presses the Right key, heuristics determine whether there is an element they might be trying to reach towards the right and which element they probably want. Disabled by default.
QWebEngineSettings::LocalContentCanAccessFileUrls9Allows locally loaded documents to access other local URLs. Disabling this makes QtWebEngine behave more like Chrome and Firefox does by default. Enabled by default.
QWebEngineSettings::HyperlinkAuditingEnabled10Enables support for the ping attribute for hyperlinks. Disabled by default.
QWebEngineSettings::ScrollAnimatorEnabled11Enables animated scrolling. Disabled by default.
QWebEngineSettings::ErrorPageEnabled12Enables displaying the built-in error pages of Chromium. Enabled by default.
QWebEngineSettings::PluginsEnabled13Enables support for Pepper plugins, such as the Flash player. Disabled by default.
QWebEngineSettings::FullScreenSupportEnabled14Enables fullscreen support in an application. Disabled by default. (Added in Qt 5.6)
QWebEngineSettings::ScreenCaptureEnabled15Enables screen capture in an application. Disabled by default. (Added in Qt 5.7)
QWebEngineSettings::WebGLEnabled16Enables support for HTML 5 WebGL. Enabled by default if available. (Added in Qt 5.7)
QWebEngineSettings::Accelerated2dCanvasEnabled17Specifies whether the HTML5 2D canvas should be a OpenGL framebuffer. This makes many painting operations faster, but slows down pixel access. Enabled by default if available. (Added in Qt 5.7)
QWebEngineSettings::AutoLoadIconsForPage18Automatically downloads icons for web pages. Enabled by default. (Added in Qt 5.7)
QWebEngineSettings::TouchIconsEnabled19Enables support for touch icons and precomposed touch icons Disabled by default. (Added in Qt 5.7)
QWebEngineSettings::FocusOnNavigationEnabled20Gives focus to the view associated with the page, whenever a navigation operation occurs (load, stop, reload, reload and bypass cache, forward, backward, set content, and so on). Disabled by default. (Added in Qt 5.8)
QWebEngineSettings::PrintElementBackgrounds21Turns on printing of CSS backgrounds when printing a web page. Enabled by default. (Added in Qt 5.8)
QWebEngineSettings::AllowRunningInsecureContent22By default, HTTPS pages cannot run JavaScript, CSS, plugins or web-sockets from HTTP URLs. This provides an override to get the old insecure behavior. Disabled by default. (Added in Qt 5.8)
QWebEngineSettings::AllowGeolocationOnInsecureOrigins23Since Qt 5.7, only secure origins such as HTTPS have been able to request Geolocation features. This provides an override to allow non secure origins to access Geolocation again. Disabled by default. (Added in Qt 5.9)
QWebEngineSettings::AllowWindowActivationFromJavaScript24Allows activating windows by using the window.focus() JavaScript method. Disabled by default. (Added in Qt 5.10)
QWebEngineSettings::ShowScrollBars25Shows scroll bars. Enabled by default. (Added in Qt 5.10)
QWebEngineSettings::PlaybackRequiresUserGesture26Inhibits playback of media content until the user interacts with the page. By default, WebEngine uses Chromium settings, as described in Autoplay Policy Changes. This is similar to how Chrome on Android behaves, while the default behavior when it is disabled is similar to Chrome on desktops. To overwrite the default behavior, disable this setting. (Added in Qt 5.11)
QWebEngineSettings::JavascriptCanPaste28Allows JavaScript programs to read (paste) from the clipboard and to write unsanitized content. A sanitized write is done with the write and writeText JavaScript Clipboard API calls and must be accompanied by user action; unsanitized writes are any writes which do not meet these criteria. For this setting to have any effect, JavascriptCanAccessClipboard must also be enabled. Since unrestricted clipboard access is a potential security concern, it is recommended that applications leave this disabled and instead respond to ClipboardReadWrite feature permission requests. Disabled by default. (Added in Qt 5.11)
QWebEngineSettings::WebRTCPublicInterfacesOnly27Limits WebRTC to public IP addresses only. When disabled WebRTC may also use local network IP addresses, but remote hosts can also see your local network IP address. Disabled by default. (Added in Qt 5.11)
QWebEngineSettings::DnsPrefetchEnabled29Specifies whether WebEngine will try to pre-fetch DNS entries to speed up browsing. Disabled by default. (Added in Qt 5.12)
QWebEngineSettings::PdfViewerEnabled30Specifies that PDF documents will be opened in the internal PDF viewer instead of being downloaded. Enabled by default. (Added in Qt 5.13)
QWebEngineSettings::NavigateOnDropEnabled31Specifies that navigations can be triggered by dropping URLs on the view. Enabled by default. (Added in Qt 6.4)
QWebEngineSettings::ReadingFromCanvasEnabled32Specifies that reading from all canvas elements is enabled. This setting will have impact on all HTML5 canvas elements irrespective of origin, and can be disabled to prevent canvas fingerprinting. Enabled by default. (Added in Qt 6.6)
QWebEngineSettings::ForceDarkMode33Specifies that all web contents will be rendered using a dark theme. For more information, see Auto dark theme. Disabled by default. (Added in Qt 6.7)

Member Function Documentation

QString QWebEngineSettings::defaultTextEncoding() const

Returns the default text encoding.

See also setDefaultTextEncoding().

QString QWebEngineSettings::fontFamily(QWebEngineSettings::FontFamily which) const

Returns the actual font family for the specified generic font family, which.

int QWebEngineSettings::fontSize(QWebEngineSettings::FontSize type) const

Returns the default font size for type in pixels.

See also setFontSize().

[since Qt 6.8] QWebEngineSettings::ImageAnimationPolicy QWebEngineSettings::imageAnimationPolicy() const

Returns the currently selected policy for handling image animation when the image frames are rendered. Default is QWebEngineSettings::ImageAnimationPolicy::Allow.

This function was introduced in Qt 6.8.

See also setImageAnimationPolicy and resetImageAnimationPolicy.

void QWebEngineSettings::resetAttribute(QWebEngineSettings::WebAttribute attribute)

Resets the setting of attribute to the value specified in the profile that the page belongs to.

void QWebEngineSettings::resetFontFamily(QWebEngineSettings::FontFamily which)

Resets the actual font family specified by which to the one specified in the profile that the page belongs to.

void QWebEngineSettings::resetFontSize(QWebEngineSettings::FontSize type)

Resets the font size for type to the size specified in the profile that the page belongs to.

[since Qt 6.8] void QWebEngineSettings::resetImageAnimationPolicy()

Removes the policy for handling image animation.

This function was introduced in Qt 6.8.

See also imageAnimationPolicy and setImageAnimationPolicy.

[since Qt 5.11] void QWebEngineSettings::resetUnknownUrlSchemePolicy()

Removes the policy for handling navigation requests to URLs with unknown schemes.

This function was introduced in Qt 5.11.

See also unknownUrlSchemePolicy and setUnknownUrlSchemePolicy.

void QWebEngineSettings::setAttribute(QWebEngineSettings::WebAttribute attribute, bool on)

Enables or disables the specified attribute feature depending on the value of on.

void QWebEngineSettings::setDefaultTextEncoding(const QString &encoding)

Specifies the default text encoding system.

The value of encoding must be a string describing an encoding such as "utf-8" or "iso-8859-1". If left empty, a default value will be used. For a more extensive list of encoding names see QTextCodec.

See also defaultTextEncoding().

void QWebEngineSettings::setFontSize(QWebEngineSettings::FontSize type, int size)

Sets the font size for type to size in pixels.

See also fontSize().

[since Qt 6.8] void QWebEngineSettings::setImageAnimationPolicy(QWebEngineSettings::ImageAnimationPolicy policy)

Sets the policy for handling image animation when the image frames are rendered to policy. Default is QWebEngineSettings::ImageAnimationPolicy::Allow.

This function was introduced in Qt 6.8.

See also imageAnimationPolicy and resetImageAnimationPolicy.

[since Qt 5.11] void QWebEngineSettings::setUnknownUrlSchemePolicy(QWebEngineSettings::UnknownUrlSchemePolicy policy)

Sets the policy for handling navigation requests to URLs with unknown schemes to policy. Default is QWebEngineSettings::AllowUnknownUrlSchemesFromUserInteraction.

This function was introduced in Qt 5.11.

See also unknownUrlSchemePolicy and resetUnknownUrlSchemePolicy.

bool QWebEngineSettings::testAttribute(QWebEngineSettings::WebAttribute attribute) const

Returns true if attribute is enabled; otherwise returns false.

[since Qt 5.11] QWebEngineSettings::UnknownUrlSchemePolicy QWebEngineSettings::unknownUrlSchemePolicy() const

Returns the currently selected policy for handling navigation requests to URLs with unknown schemes. Default is QWebEngineSettings::AllowUnknownUrlSchemesFromUserInteraction.

This function was introduced in Qt 5.11.

See also setUnknownUrlSchemePolicy and resetUnknownUrlSchemePolicy.