Skip to main content

class QCefView

class QCefView
: public QWidget

Represents the CEF browser view.

Summary

MembersDescriptions
public QCefView(const QString & url, const QCefSetting * setting, QWidget * parent, Qt::WindowFlags f)Constructs a QCefView instance.
public QCefView(QWidget * parent, Qt::WindowFlags f)Constructs a QCefView instance.
public ~QCefView()Destructs the QCefView instance.
public void addLocalFolderResource(const QString & path, const QString & url, int priority)Adds a url mapping item with local web resource directory.
public void addArchiveResource(const QString & path, const QString & url, const QString & password, int priority)Adds a url mapping item with local archive (.zip) file which contains the web resource.
public int browserId()Gets the browser id.
public void navigateToString(const QString & content)Navigates to the content.
public void navigateToUrl(const QString & url)Navigates to the URL.
public bool browserCanGoBack()Checks whether the browser can go back.
public bool browserCanGoForward()Checks whether the browser can go forward.
public void browserGoBack()Requires the browser to go back.
public void browserGoForward()Requires the browser to go forward.
public bool browserIsLoading()Checks whether the browser is loading.
public void browserReload()Requires the browser to reload.
public void browserStopLoad()Requires the browser to stop load.
public bool triggerEvent(const QCefEvent & event)Triggers the event for main frame.
public bool triggerEvent(const QCefEvent & event, qint64 frameId)Triggers the event for specified frame.
public bool broadcastEvent(const QCefEvent & event)Broad cast the event for all frames.
public bool responseQCefQuery(const QCefQuery & query)Response the QCefQuery request.
public bool executeJavascript(qint64 frameId, const QString & code, const QString & url)Executes javascript code in specified frame, this method does not report the result of the javascript. To get the result of the javascript execution use executeJavascriptWithResult
public bool executeJavascriptWithResult(qint64 frameId, const QString & code, const QString & url, const QString & context)Executes javascript code in specified frame and the result will be reported through reportJavascriptResult signal.
public bool setPreference(const QString & name, const QVariant & value, const QString & error)Sets the preference for this browser.
public void setDisablePopupContextMenu(bool disable)Sets whether to disable the context menu for popup browser.
public bool isPopupContextMenuDisabled()Gets whether to disable the context menu for popup browser.
public bool hasDevTools()Detects whether this browser has a devtools opened.
public void showDevTools()Opens the devtools dialog.
public void closeDevTools()Closes the devtools dialog.
public void setEnableDragAndDrop(bool enable)Sets whether to enable drag and drop.
public bool isDragAndDropEnabled() constGets whether to enable drag and drop.
public void setFocus(Qt::FocusReason reason)Please refer to QWidget::setFocus.
public QVariant inputMethodQuery(Qt::InputMethodQuery query) constPlease refer to QWidget::inputMethodQuery.
public void render(QPainter * painter)Renders the view content to target painter.
protected virtual QCefView*onNewBrowser(qint64 sourceFrameId, const QString & url, const QString & name, QCefView::CefWindowOpenDispositiontargetDisposition, QRect & rect,QCefSetting & settings)Gets called before a new browser created (only for browser created by non-JavaScript)
protected virtual bool onNewPopup(qint64 frameId, const QString & targetUrl, QString & targetFrameName, QCefView::CefWindowOpenDispositiontargetDisposition, QRect & rect,QCefSetting & settings, bool & disableJavascriptAccess)Gets called before the popup browser created (only for browser created by JavaScript)
protected virtual void onNewDownloadItem(const QSharedPointer< QCefDownloadItem > & item, const QString & suggestedName)Gets called on new download item was required. Keep reference to the download item and call QCefDownloadItem::start method to allow and start the download, Ignore the download item to disallow the download.
protected virtual void onUpdateDownloadItem(const QSharedPointer< QCefDownloadItem > & item)Gets called on download item updated. To get this method called QCefDownloadItem::start method must be called in newDownloadItem method.
protected virtual bool onRequestCloseFromWeb()Gets called on close request from web.
protected void paintEvent(QPaintEvent * event)Please refer to QWidget::paintEvent.
protected void inputMethodEvent(QInputMethodEvent * event)Please refer to QWidget::inputMethodEvent.
protected void showEvent(QShowEvent * event)Please refer to QWidget::showEvent.
protected void hideEvent(QHideEvent * event)Please refer to QWidget::hideEvent.
protected void focusInEvent(QFocusEvent * event)Please refer to QWidget::focusInEvent.
protected void focusOutEvent(QFocusEvent * event)Please refer to QWidget::focusOutEvent.
protected void resizeEvent(QResizeEvent * event)Please refer to QWidget::resizeEvent.
protected void keyPressEvent(QKeyEvent * event)Please refer to QWidget::keyPressEvent.
protected void keyReleaseEvent(QKeyEvent * event)Please refer to QWidget::keyReleaseEvent.
protected void mouseMoveEvent(QMouseEvent * event)Please refer to QWidget::mouseMoveEvent.
protected void mousePressEvent(QMouseEvent * event)Please refer to QWidget::mousePressEvent.
protected void mouseReleaseEvent(QMouseEvent * event)Please refer to QWidget::mouseReleaseEvent.
protected void wheelEvent(QWheelEvent * event)Please refer to QWidget::wheelEvent.
protected void contextMenuEvent(QContextMenuEvent * event)Please refer to QWidget::contextMenuEvent.
{signal} public void loadingStateChanged(int browserId, bool isLoading, bool canGoBack, bool canGoForward)Gets called on loading state changed.
{signal} public void loadStart(int browserId, qint64 frameId, bool isMainFrame, int transitionType)Gets called on loading starts.
{signal} public void loadEnd(int browserId, qint64 frameId, bool isMainFrame, int httpStatusCode)Gets called on loading ends.
{signal} public void loadError(int browserId, qint64 frameId, bool isMainFrame, int errorCode, const QString & errorMsg, const QString & failedUrl)Gets called on loading failed due to error.
{signal} public void draggableRegionChanged(const QRegion & draggableRegion, const QRegion & nonDraggableRegion)Gets called on draggable region changed.
{signal} public void addressChanged(qint64 frameId, const QString & url)Gets called on the address changed.
{signal} public void titleChanged(const QString & title)Gets called on title changed.
{signal} public void faviconURLChanged(const QStringList & urls)Gets called on favicon url changed.
{signal} public void fullscreenModeChanged(bool fullscreen)Gets called on fullscreen mode changed.
{signal} public void statusMessage(const QString & message)Gets called on status message changed.
{signal} public void consoleMessage(const QString & message, int level)Gets called on console message from the web content.
{signal} public void loadingProgressChanged(double progress)Gets called on loading progress changed.
{signal} public void cefQueryRequest(int browserId, qint64 frameId, const QCefQuery & query)Gets called on new QCefQuery request.
{signal} public void invokeMethod(int browserId, qint64 frameId, const QString & method, const QVariantList & arguments)Gets called on invoking method request from web content(Javascript)
{signal} public void reportJavascriptResult(int browserId, qint64 frameId, const QString & context, const QVariant & result)Gets called on the result of the javascript executed with executeJavascriptWithResult returned.
{signal} public void nativeBrowserCreated(QWindow * window)Gets called after the native browser window created. This slot does not work for OSR mode.
{slot} public inline void setFocus()
enum CefWindowOpenDispositionRepresents the CEF popup windows open disposition.
private QScopedPointer< QCefViewPrivate > d_ptr

Members


public QCefView(const QString & url, const QCefSetting * setting, QWidget * parent, Qt::WindowFlags f)

Constructs a QCefView instance.

Parameters

  • url The target url

  • setting The QCefSetting instance

  • parent The parent

  • f The Qt WindowFlags


public QCefView(QWidget * parent, Qt::WindowFlags f)

Constructs a QCefView instance.

Parameters

  • parent The parent

  • f The Qt WindowFlags


public ~QCefView()

Destructs the QCefView instance.


public void addLocalFolderResource(const QString & path, const QString & url, int priority)

Adds a url mapping item with local web resource directory.

Parameters

  • path The path to the local resource directory

  • url The url to be mapped to

  • priority The priority


public void addArchiveResource(const QString & path, const QString & url, const QString & password, int priority)

Adds a url mapping item with local archive (.zip) file which contains the web resource.

Parameters

  • path The path to the local archive file

  • url The url to be mapped to

  • password The password of the archive

  • priority The priority


public int browserId()

Gets the browser id.

Returns

The browser id


public void navigateToString(const QString & content)

Navigates to the content.

Parameters

  • content The content

public void navigateToUrl(const QString & url)

Navigates to the URL.

Parameters

  • url The url

public bool browserCanGoBack()

Checks whether the browser can go back.

Returns

True if can; otherwise false


public bool browserCanGoForward()

Checks whether the browser can go forward.

Returns

True if can; otherwise false


public void browserGoBack()

Requires the browser to go back.


public void browserGoForward()

Requires the browser to go forward.


public bool browserIsLoading()

Checks whether the browser is loading.

Returns

True if it is loading; otherwise false


public void browserReload()

Requires the browser to reload.


public void browserStopLoad()

Requires the browser to stop load.


public bool triggerEvent(const QCefEvent & event)

Triggers the event for main frame.

Parameters

Returns

True on successful; otherwise false


public bool triggerEvent(const QCefEvent & event, qint64 frameId)

Triggers the event for specified frame.

Parameters

  • event The QCefEvent instance

  • frameId The frame id

Returns

True on successful; otherwise false


public bool broadcastEvent(const QCefEvent & event)

Broad cast the event for all frames.

Parameters

Returns

True on successful; otherwise false


public bool responseQCefQuery(const QCefQuery & query)

Response the QCefQuery request.

Parameters

  • query The query instance

Returns

True on successful; otherwise false


public bool executeJavascript(qint64 frameId, const QString & code, const QString & url)

Executes javascript code in specified frame, this method does not report the result of the javascript. To get the result of the javascript execution use executeJavascriptWithResult

Parameters

  • frameId The frame id

  • code The javascript code

  • url The URL where the script in question can be found, if any. The renderer may request this URL to show the developer the source of the error

Returns

True on successful; otherwise false


public bool executeJavascriptWithResult(qint64 frameId, const QString & code, const QString & url, const QString & context)

Executes javascript code in specified frame and the result will be reported through reportJavascriptResult signal.

Parameters

  • frameId The frame id

  • code The javascript code

  • url The URL where the script in question can be found, if any. The renderer may request this URL to show the developer the source of the error

  • context The context used to identify the one execution

Returns

True on successful; otherwise false


public bool setPreference(const QString & name, const QVariant & value, const QString & error)

Sets the preference for this browser.

Parameters

  • name The preference name

  • value The preference value, if this value is QVariant::UnknownType or QVariant::Invalid, the preference will be restored to default value

  • error The error message populated on failure

Returns

True on successful; otherwise false


public void setDisablePopupContextMenu(bool disable)

Sets whether to disable the context menu for popup browser.

Parameters

  • disable True to disable; otherwise false

public bool isPopupContextMenuDisabled()

Gets whether to disable the context menu for popup browser.

Returns

True to disable; otherwise false


public bool hasDevTools()

Detects whether this browser has a devtools opened.

Returns

True if opend already; otherwise false


public void showDevTools()

Opens the devtools dialog.


public void closeDevTools()

Closes the devtools dialog.


public void setEnableDragAndDrop(bool enable)

Sets whether to enable drag and drop.

Parameters

  • enable True to enable; otherwise false

This function does not work for OSR mode. There is a problem, when dragging a file to a non dragging area, the content of the file will be displayed. You need to solve the problem yourself.


public bool isDragAndDropEnabled() const

Gets whether to enable drag and drop.

Returns

True to enable; otherwise false


public void setFocus(Qt::FocusReason reason)

Please refer to QWidget::setFocus.


public QVariant inputMethodQuery(Qt::InputMethodQuery query) const

Please refer to QWidget::inputMethodQuery.


public void render(QPainter * painter)

Renders the view content to target painter.

Parameters

  • painter The target painter

protected virtual QCefView*onNewBrowser(qint64 sourceFrameId, const QString & url, const QString & name, QCefView::CefWindowOpenDispositiontargetDisposition, QRect & rect,QCefSetting & settings)

Gets called before a new browser created (only for browser created by non-JavaScript)

Parameters

  • frameId The source frame id

  • url The target URL

  • name The target name

  • targetDisposition Target window open method

  • rect Rect to be used for the popup

  • settings Settings to be used for the popup

Returns

True to cancel the popup; false to allow


protected virtual bool onNewPopup(qint64 frameId, const QString & targetUrl, QString & targetFrameName, QCefView::CefWindowOpenDispositiontargetDisposition, QRect & rect,QCefSetting & settings, bool & disableJavascriptAccess)

Gets called before the popup browser created (only for browser created by JavaScript)

Parameters

  • frameId The source frame id

  • targetUrl The target URL

  • targetFrameName The target name

  • targetDisposition Target window open method

  • rect Rect to be used for the popup

  • settings Settings to be used for the popup

Returns

True to cancel the popup; false to allow


protected virtual void onNewDownloadItem(const QSharedPointer< QCefDownloadItem > & item, const QString & suggestedName)

Gets called on new download item was required. Keep reference to the download item and call QCefDownloadItem::start method to allow and start the download, Ignore the download item to disallow the download.

Parameters

  • item The new download item

  • suggestedName The new suggested name


protected virtual void onUpdateDownloadItem(const QSharedPointer< QCefDownloadItem > & item)

Gets called on download item updated. To get this method called QCefDownloadItem::start method must be called in newDownloadItem method.

Parameters

  • item The download item

protected virtual bool onRequestCloseFromWeb()

Gets called on close request from web.

Returns

True to allow the close, false to cancel the close


protected void paintEvent(QPaintEvent * event)

Please refer to QWidget::paintEvent.


protected void inputMethodEvent(QInputMethodEvent * event)

Please refer to QWidget::inputMethodEvent.


protected void showEvent(QShowEvent * event)

Please refer to QWidget::showEvent.


protected void hideEvent(QHideEvent * event)

Please refer to QWidget::hideEvent.


protected void focusInEvent(QFocusEvent * event)

Please refer to QWidget::focusInEvent.


protected void focusOutEvent(QFocusEvent * event)

Please refer to QWidget::focusOutEvent.


protected void resizeEvent(QResizeEvent * event)

Please refer to QWidget::resizeEvent.


protected void keyPressEvent(QKeyEvent * event)

Please refer to QWidget::keyPressEvent.


protected void keyReleaseEvent(QKeyEvent * event)

Please refer to QWidget::keyReleaseEvent.


protected void mouseMoveEvent(QMouseEvent * event)

Please refer to QWidget::mouseMoveEvent.


protected void mousePressEvent(QMouseEvent * event)

Please refer to QWidget::mousePressEvent.


protected void mouseReleaseEvent(QMouseEvent * event)

Please refer to QWidget::mouseReleaseEvent.


protected void wheelEvent(QWheelEvent * event)

Please refer to QWidget::wheelEvent.


protected void contextMenuEvent(QContextMenuEvent * event)

Please refer to QWidget::contextMenuEvent.


{signal} public void loadingStateChanged(int browserId, bool isLoading, bool canGoBack, bool canGoForward)

Gets called on loading state changed.

Parameters

  • browserId Indicates the browser id

  • isLoading Indicates the browser is loading

  • canGoBack Indicates the browser can go back

  • canGoForward Indicates the browser can go forward


{signal} public void loadStart(int browserId, qint64 frameId, bool isMainFrame, int transitionType)

Gets called on loading starts.

Parameters

  • browserId Indicates the browser id

  • frameId Indicates the frame id

  • isMainFrame Indicates the whether this is the main frame

  • transitionType transition type


{signal} public void loadEnd(int browserId, qint64 frameId, bool isMainFrame, int httpStatusCode)

Gets called on loading ends.

Parameters

  • browserId Indicates the browser id

  • frameId Indicates the frame id

  • isMainFrame Indicates the whether this is the main frame

  • httpStatusCode The HTTP status code


{signal} public void loadError(int browserId, qint64 frameId, bool isMainFrame, int errorCode, const QString & errorMsg, const QString & failedUrl)

Gets called on loading failed due to error.

Parameters

  • browserId Indicates the browser id

  • frameId Indicates the frame id

  • isMainFrame Indicates the whether this is the main frame

  • errorCode The error code

  • errorMsg The error message

  • failedUrl The url caused the failure


{signal} public void draggableRegionChanged(const QRegion & draggableRegion, const QRegion & nonDraggableRegion)

Gets called on draggable region changed.

Parameters

  • draggableRegion The new draggable region

  • nonDraggableRegion The new non-draggable region


{signal} public void addressChanged(qint64 frameId, const QString & url)

Gets called on the address changed.

Parameters

  • frameId The frame id

  • url The address


{signal} public void titleChanged(const QString & title)

Gets called on title changed.

Parameters

  • title The title

{signal} public void faviconURLChanged(const QStringList & urls)

Gets called on favicon url changed.

Parameters

  • urls The urls

{signal} public void fullscreenModeChanged(bool fullscreen)

Gets called on fullscreen mode changed.

Parameters

  • fullscreen The current fullscreen mode

{signal} public void statusMessage(const QString & message)

Gets called on status message changed.

Parameters

  • message The status message

{signal} public void consoleMessage(const QString & message, int level)

Gets called on console message from the web content.

Parameters

  • message The message

  • level The level


{signal} public void loadingProgressChanged(double progress)

Gets called on loading progress changed.

Parameters

  • progress Current progress

{signal} public void cefQueryRequest(int browserId, qint64 frameId, const QCefQuery & query)

Gets called on new QCefQuery request.

Parameters

  • browserId The browser id

  • frameId The frame id

  • query The query request


{signal} public void invokeMethod(int browserId, qint64 frameId, const QString & method, const QVariantList & arguments)

Gets called on invoking method request from web content(Javascript)

Parameters

  • browserId The browser id

  • frameId The frame id

  • method The method name

  • arguments The arguments list


{signal} public void reportJavascriptResult(int browserId, qint64 frameId, const QString & context, const QVariant & result)

Gets called on the result of the javascript executed with executeJavascriptWithResult returned.

Parameters

  • browserId The browser id

  • frameId The frame id

  • context The context

  • result The result


{signal} public void nativeBrowserCreated(QWindow * window)

Gets called after the native browser window created. This slot does not work for OSR mode.

Parameters

  • window The native browser windows

{slot} public inline void setFocus()


enum CefWindowOpenDisposition

Represents the CEF popup windows open disposition.

ValuesDescriptions
CefWindowOpenDispositionUnknown
CefWindowOpenDispositionCurrentTab
CefWindowOpenDispositionSingletonTab
CefWindowOpenDispositionNewForeGroundTab
CefWindowOpenDispositionNewBackgroundTab
CefWindowOpenDispositionNewPopup
CefWindowOpenDispositionNewWindow
CefWindowOpenDispositionSaveToDisk
CefWindowOpenDispositionOffTheRecord
CefWindowOpenDispositionIgnoreAction

private QScopedPointer< QCefViewPrivate > d_ptr