QWebSettings Class Reference

#include <mw/QtWebKit/qwebsettings.h>

class QWebSettings

The QWebSettings class provides an object to store the settings used by QWebPage and QWebFrame.

Public Member Enumerations
enumFontFamily { StandardFont, FixedFont, SerifFont, SansSerifFont, ..., FantasyFont }
enumFontSize { MinimumFontSize, MinimumLogicalFontSize, DefaultFontSize, DefaultFixedFontSize }
enumWebAttribute { AutoLoadImages, JavascriptEnabled, JavaEnabled, PluginsEnabled, ..., JavascriptCanCloseWindows }
enumWebGraphic { MissingImageGraphic, MissingPluginGraphic, DefaultFrameIconGraphic, TextAreaSizeGripCornerGraphic, DeleteButtonGraphic }
Public Member Functions
voidclearIconDatabase()
voidclearMemoryCaches()
QString defaultTextEncoding()
voidenablePersistentStorage(const QString &)
QString fontFamily(FontFamily)
intfontSize(FontSize)
QWebSettings *globalSettings()
QWebSettingsPrivate *handle()
QString iconDatabasePath()
QIcon iconForUrl(const QUrl &)
QString localStoragePath()
intmaximumPagesInCache()
qint64 offlineStorageDefaultQuota()
QString offlineStoragePath()
QString offlineWebApplicationCachePath()
qint64 offlineWebApplicationCacheQuota()
voidresetAttribute(WebAttribute)
voidresetFontFamily(FontFamily)
voidresetFontSize(FontSize)
voidsetAttribute(WebAttribute, bool)
voidsetDefaultTextEncoding(const QString &)
voidsetFontFamily(FontFamily, const QString &)
voidsetFontSize(FontSize, int)
voidsetIconDatabasePath(const QString &)
voidsetLocalStoragePath(const QString &)
voidsetMaximumPagesInCache(int)
voidsetObjectCacheCapacities(int, int, int)
voidsetOfflineStorageDefaultQuota(qint64)
voidsetOfflineStoragePath(const QString &)
voidsetOfflineWebApplicationCachePath(const QString &)
voidsetOfflineWebApplicationCacheQuota(qint64)
voidsetUserStyleSheetUrl(const QUrl &)
voidsetWebGraphic(WebGraphic, const QPixmap &)
booltestAttribute(WebAttribute)
QUrl userStyleSheetUrl()
QPixmap webGraphic(WebGraphic)

Detailed Description

Since
4.4 QtWebKit
Each QWebPage object has its own QWebSettings object, which configures the settings for that page. If a setting is not configured, then it is looked up in the global settings object, which can be accessed using globalSettings().

QWebSettings allows configuration of browser properties, such as font sizes and families, the location of a custom style sheet, and generic attributes like JavaScript and plugins. Individual attributes are set using the setAttribute() function. The {QWebSettings::WebAttribute}{WebAttribute} enum further describes each attribute.

QWebSettings also configures global properties such as the web page memory cache, icon database, local database storage and offline applications storage.

Member Enumeration Documentation

Enum FontFamily

This enum describes the generic font families defined by CSS 2. For more information see the {http://www.w3.org/TR/REC-CSS2/fonts.html#generic-font-families}{CSS standard}.

StandardFont FixedFont SerifFont SansSerifFont CursiveFont FantasyFont

Enum FontSize

This enum describes the font sizes configurable through QWebSettings.

MinimumFontSize The hard minimum font size. MinimumLogicalFontSize The minimum logical font size that is applied when zooming out with QWebFrame::setTextSizeMultiplier(). DefaultFontSize The default font size for regular text. DefaultFixedFontSize The default font size for fixed-pitch text.

Enum WebAttribute

This enum describes various attributes that are configurable through QWebSettings.

AutoLoadImages Specifies whether images are automatically loaded in web pages. This is enabled by default. DnsPrefetchEnabled Specifies whether QtWebkit will try to pre-fetch DNS entries to speed up browsing. This only works as a global attribute. Only for Qt 4.6 and later. This is disabled by default. JavascriptEnabled Enables or disables the running of JavaScript programs. This is enabled by default JavaEnabled Enables or disables Java applets. Currently Java applets are not supported. PluginsEnabled Enables or disables plugins in Web pages (e.g. using NPAPI). Qt plugins with a mimetype such as "application/x-qt-plugin" are not affected by this setting. This is disabled by default. PrivateBrowsingEnabled Private browsing prevents WebKit from recording visited pages in the history and storing web page icons. This is disabled by default. JavascriptCanOpenWindows Specifies whether JavaScript programs can open new windows. This is disabled by default. JavascriptCanCloseWindows Specifies whether JavaScript programs can close windows. This is disabled by default. JavascriptCanAccessClipboard Specifies whether JavaScript programs can read or write to the clipboard. This is disabled by default. DeveloperExtrasEnabled Enables extra tools for Web developers. Currently this enables the "Inspect" element in the context menu as well as the use of QWebInspector which controls the web inspector for web site debugging. This is disabled by default. SpatialNavigationEnabled Enables or disables the Spatial Navigation feature, which consists in the ability to navigate between focusable elements in a Web page, such as hyperlinks and form controls, by using Left, Right, Up and Down arrow keys. For example, if a user presses the Right key, heuristics determine whether there is an element he might be trying to reach towards the right and which element he probably wants. This is disabled by default. LinksIncludedInFocusChain Specifies whether hyperlinks should be included in the keyboard focus chain. This is enabled by default. ZoomTextOnly Specifies whether the zoom factor on a frame applies only to the text or to all content. This is disabled by default. PrintElementBackgrounds Specifies whether the background color and images are also drawn when the page is printed. This is enabled by default. OfflineStorageDatabaseEnabled Specifies whether support for the HTML 5 offline storage feature is enabled or not. This is disabled by default. OfflineWebApplicationCacheEnabled Specifies whether support for the HTML 5 web application cache feature is enabled or not. This is disabled by default. LocalStorageEnabled Specifies whether support for the HTML 5 local storage feature is enabled or not. This is disabled by default. LocalStorageDatabaseEnabled {This enum value is deprecated.} Use QWebSettings::LocalStorageEnabled instead. LocalContentCanAccessRemoteUrls Specifies whether locally loaded documents are allowed to access remote urls. This is disabled by default. For more information about security origins and local vs. remote content see QWebSecurityOrigin. LocalContentCanAccessFileUrls Specifies whether locally loaded documents are allowed to access other local urls. This is enabled by default. For more information about security origins and local vs. remote content see QWebSecurityOrigin. XSSAuditingEnabled Specifies whether load requests should be monitored for cross-site scripting attempts. Suspicious scripts will be blocked and reported in the inspector's JavaScript console. Enabling this feature might have an impact on performance and it is disabled by default. AcceleratedCompositingEnabled This feature, when used in conjunction with QGraphicsWebView, accelerates animations of web content. CSS animations of the transform and opacity properties will be rendered by composing the cached content of the animated elements. This is enabled by default. TiledBackingStoreEnabled This setting enables the tiled backing store feature for a QGraphicsWebView. With the tiled backing store enabled, the web page contents in and around the current visible area is speculatively cached to bitmap tiles. The tiles are automatically kept in sync with the web page as it changes. Enabling tiling can significantly speed up painting heavy operations like scrolling. Enabling the feature increases memory consumption. It does not work well with contents using CSS fixed positioning (see also {QGraphicsWebView::}{resizesToContents} property). {QGraphicsWebView::}{tiledBackingStoreFrozen} property allows application to temporarily freeze the contents of the backing store. This is disabled by default. FrameFlatteningEnabled With this setting each subframe is expanded to its contents. On touch devices, it is desired to not have any scrollable sub parts of the page as it results in a confusing user experience, with scrolling sometimes scrolling sub parts and at other times scrolling the page itself. For this reason iframes and framesets are barely usable on touch devices. This will flatten all the frames to become one scrollable page. This is disabled by default. SiteSpecificQuirksEnabled This setting enables WebKit's workaround for broken sites. It is enabled by default.

Enum WebGraphic

This enums describes the standard graphical elements used in webpages.

MissingImageGraphic The replacement graphic shown when an image could not be loaded. MissingPluginGraphic The replacement graphic shown when a plugin could not be loaded. DefaultFrameIconGraphic The default icon for QWebFrame::icon(). TextAreaSizeGripCornerGraphic The graphic shown for the size grip of text areas. DeleteButtonGraphic The graphic shown for the WebKit-Editing-Delete-Button in Deletion UI.

Member Function Documentation

clearIconDatabase ( )

voidclearIconDatabase()[static]

Clears the icon database.

clearMemoryCaches ( )

voidclearMemoryCaches()[static]

Frees up as much memory as possible by cleaning all memory caches such as page, object and font cache.

Since
4.6

defaultTextEncoding ( )

QString defaultTextEncoding()const
Since
4.6 Returns the default text encoding.

See also: setDefaultTextEncoding()

enablePersistentStorage ( const QString & )

voidenablePersistentStorage(const QString &path = QString())[static]
Since
4.6
Enables WebKit data persistence and sets the path to path. If path is empty, the user-specific data location specified by {QDesktopServices::DataLocation}{DataLocation} will be used instead.

This method will simultaneously set and enable the iconDatabasePath(), localStoragePath(), offlineStoragePath() and offlineWebApplicationCachePath().

See also: localStoragePath()

fontFamily ( FontFamily )

QString fontFamily(FontFamilywhich)const

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

fontSize ( FontSize )

intfontSize(FontSizetype)const

Returns the default font size for type.

globalSettings ( )

QWebSettings *globalSettings()[static]

Returns the global settings object.

Any setting changed on the default object is automatically applied to all QWebPage instances where the particular setting is not overriden already.

handle ( )

QWebSettingsPrivate *handle()const [inline]

iconDatabasePath ( )

QString iconDatabasePath()[static]

Returns the path of the icon database or an empty string if the icon database is disabled.

See also: setIconDatabasePath(), clearIconDatabase()

iconForUrl ( const QUrl & )

QIcon iconForUrl(const QUrl &url)[static]

Returns the web site's icon for url.

If the web site does not specify an icon OR if the icon is not in the database, a null QIcon is returned.

Note:

The returned icon's size is arbitrary.

See also: setIconDatabasePath()

localStoragePath ( )

QString localStoragePath()const
Since
4.6
Returns the path for HTML5 local storage.

See also: setLocalStoragePath()

maximumPagesInCache ( )

intmaximumPagesInCache()[static]

Returns the maximum number of web pages that are kept in the memory cache.

offlineStorageDefaultQuota ( )

qint64 offlineStorageDefaultQuota()[static]
Since
4.5
Returns the value of the default quota for new offline storage databases.

offlineStoragePath ( )

QString offlineStoragePath()[static]
Since
4.5
Returns the path of the HTML5 client-side database storage or an empty string if the feature is disabled.

See also: setOfflineStoragePath()

offlineWebApplicationCachePath ( )

QString offlineWebApplicationCachePath()[static]
Since
4.6
Returns the path of the HTML5 offline web application cache storage or an empty string if the feature is disabled.

See also: setOfflineWebApplicationCachePath()

offlineWebApplicationCacheQuota ( )

qint64 offlineWebApplicationCacheQuota()[static]
Since
4.6
Returns the value of the quota for the offline web application cache.

resetAttribute ( WebAttribute )

voidresetAttribute(WebAttributeattr)

Resets the setting of attribute to the value specified in the global QWebSettings instance.

This function has no effect on the global QWebSettings instance.

See also: globalSettings()

resetFontFamily ( FontFamily )

voidresetFontFamily(FontFamilywhich)

Resets the actual font family specified by which to the one set in the global QWebSettings instance.

This function has no effect on the global QWebSettings instance.

resetFontSize ( FontSize )

voidresetFontSize(FontSizetype)

Resets the font size for type to the size specified in the global settings object.

This function has no effect on the global QWebSettings instance.

setAttribute ( WebAttribute, bool )

voidsetAttribute(WebAttributeattr,
boolon
)

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

setDefaultTextEncoding ( const QString & )

voidsetDefaultTextEncoding(const QString &encoding)
Since
4.6 Specifies the default text encoding system.
The encoding, must be a string describing an encoding such as "utf-8", "iso-8859-1", etc. If left empty a default value will be used. For a more extensive list of encoding names see {QTextCodec}

See also: defaultTextEncoding()

setFontFamily ( FontFamily, const QString & )

voidsetFontFamily(FontFamilywhich,
const QString &family
)

Sets the actual font family to family for the specified generic family, which.

setFontSize ( FontSize, int )

voidsetFontSize(FontSizetype,
intsize
)

Sets the font size for type to size.

setIconDatabasePath ( const QString & )

voidsetIconDatabasePath(const QString &location)[static]

Sets the path of the icon database to path. The icon database is used to store "favicons" associated with web sites.

path must point to an existing directory.

Setting an empty path disables the icon database.

See also: iconDatabasePath(), clearIconDatabase()

setLocalStoragePath ( const QString & )

voidsetLocalStoragePath(const QString &path)
Since
4.6
Sets the path for HTML5 local storage to path.

For more information on HTML5 local storage see the {http://www.w3.org/TR/webstorage/#the-localstorage-attribute}{Web Storage standard}.

Support for local storage can enabled by setting the {QWebSettings::LocalStorageEnabled}{LocalStorageEnabled} attribute.

See also: localStoragePath()

setMaximumPagesInCache ( int )

voidsetMaximumPagesInCache(intpages)[static]

Sets the maximum number of pages to hold in the memory page cache to pages.

The Page Cache allows for a nicer user experience when navigating forth or back to pages in the forward/back history, by pausing and resuming up to pages.

For more information about the feature, please refer to:

http://webkit.org/blog/427/webkit-page-cache-i-the-basics/

setObjectCacheCapacities ( int, int, int )

voidsetObjectCacheCapacities(intcacheMinDeadCapacity,
intcacheMaxDead,
inttotalCapacity
)[static]

Specifies the capacities for the memory cache for dead objects such as stylesheets or scripts.

The cacheMinDeadCapacity specifies the minimum number of bytes that dead objects should consume when the cache is under pressure.

cacheMaxDead is the maximum number of bytes that dead objects should consume when the cache is not under pressure.

totalCapacity specifies the maximum number of bytes that the cache should consume overall.

The cache is enabled by default. Calling setObjectCacheCapacities(0, 0, 0) will disable the cache. Calling it with one non-zero enables it again.

setOfflineStorageDefaultQuota ( qint64 )

voidsetOfflineStorageDefaultQuota(qint64maximumSize)[static]
Since
4.5
Sets the value of the default quota for new offline storage databases to maximumSize.

setOfflineStoragePath ( const QString & )

voidsetOfflineStoragePath(const QString &path)[static]
Since
4.5
Sets path as the save location for HTML5 client-side database storage data.

path must point to an existing directory.

Setting an empty path disables the feature.

Support for client-side databases can enabled by setting the {QWebSettings::OfflineStorageDatabaseEnabled}{OfflineStorageDatabaseEnabled} attribute.

See also: offlineStoragePath()

setOfflineWebApplicationCachePath ( const QString & )

voidsetOfflineWebApplicationCachePath(const QString &path)[static]
Since
4.6
Sets the path for HTML5 offline web application cache storage to path.

An application cache acts like an HTTP cache in some sense. For documents that use the application cache via JavaScript, the loader engine will first ask the application cache for the contents, before hitting the network.

The feature is described in details at: http://dev.w3.org/html5/spec/Overview.html#appcache

path must point to an existing directory.

Setting an empty path disables the feature.

Support for offline web application cache storage can enabled by setting the {QWebSettings::OfflineWebApplicationCacheEnabled}{OfflineWebApplicationCacheEnabled} attribute.

See also: offlineWebApplicationCachePath()

setOfflineWebApplicationCacheQuota ( qint64 )

voidsetOfflineWebApplicationCacheQuota(qint64maximumSize)[static]
Since
4.6
Sets the value of the quota for the offline web application cache to maximumSize.

setUserStyleSheetUrl ( const QUrl & )

voidsetUserStyleSheetUrl(const QUrl &location)

Specifies the location of a user stylesheet to load with every web page.

The location must be either a path on the local filesystem, or a data URL with UTF-8 and Base64 encoded data, such as:

"data:text/css;charset=utf-8;base64,cCB7IGJhY2tncm91bmQtY29sb3I6IHJlZCB9Ow=="

Note:

If the base64 data is not valid, the style will not be applied.

See also: userStyleSheetUrl()

setWebGraphic ( WebGraphic, const QPixmap & )

voidsetWebGraphic(WebGraphictype,
const QPixmap &graphic
)[static]

Sets graphic to be drawn when QtWebKit needs to draw an image of the given type.

For example, when an image cannot be loaded, the pixmap specified by {QWebSettings::WebGraphic}{MissingImageGraphic} is drawn instead.

See also: webGraphic()

testAttribute ( WebAttribute )

booltestAttribute(WebAttributeattr)const

Returns true if attribute is enabled; otherwise returns false.

userStyleSheetUrl ( )

QUrl userStyleSheetUrl()const

Returns the location of the user stylesheet.

See also: setUserStyleSheetUrl()

webGraphic ( WebGraphic )

QPixmap webGraphic(WebGraphictype)[static]

Returns a previously set pixmap used to draw replacement graphics of the specified type.

See also: setWebGraphic()