| QCefView 1.0.7 A QWidget-based WebView Component Integrated with CEF

Loading...
Searching...
No Matches
Public Types | Signals | Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
QCefView

Represents the CEF browser view. More...

`#include <QCefView.h>`

## Public Types
enum | CefWindowOpenDisposition
| Represents the CEF pop-up windows open disposition. More...

## Signals
void | loadingStateChanged (const int &browserId, bool isLoading, bool canGoBack, bool canGoForward)
| Gets called on loading state changed.
void | loadStart (const int &browserId, const QString &frameId, bool isMainFrame, int transitionType)
| Gets called on loading starts.
void | loadEnd (const int &browserId, const QString &frameId, bool isMainFrame, int httpStatusCode)
| Gets called on loading ends.
void | loadError (const int &browserId, const QString &frameId, bool isMainFrame, int errorCode, const QString &errorMsg, const QString &failedUrl)
| Gets called on loading failed due to error.
void | draggableRegionChanged (const QRegion &draggableRegion, const QRegion &nonDraggableRegion)
| Gets called on draggable region changed.
void | addressChanged (const QString &frameId, const QString &url)
| Gets called on the address changed.
void | titleChanged (const QString &title)
| Gets called on title changed.
void | faviconURLChanged (const QStringList &urls)
| Gets called on favicon url changed.
void | fullscreenModeChanged (bool fullscreen)
| Gets called on fullscreen mode changed.
void | statusMessage (const QString &message)
| Gets called on status message changed.
void | consoleMessage (const QString &message, int level)
| Gets called on console message from the web content.
void | loadingProgressChanged (double progress)
| Gets called on loading progress changed.
void | cefUrlRequest (const int &browserId, const QString &frameId, const QString &url)
| Gets called on built-in scheme URL access.
void | cefQueryRequest (const int &browserId, const QString &frameId, const QCefQuery &query)
| Gets called on new QCefQuery request.
void | invokeMethod (const int &browserId, const QString &frameId, const QString &method, const QVariantList &arguments)
| Gets called on invoking method request from web content(Javascript)
void | reportJavascriptResult (const int &browserId, const QString &frameId, const QString &context, const QVariant &result)
| Gets called on the result of the javascript executed with executeJavascriptWithResult returned.
void | nativeBrowserCreated (QWindow *window)
| Gets called after the native browser window created. This slot does not work for OSR mode.

## Public Member Functions
| QCefView (const QString &url, const QCefSetting *setting, QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
| Constructs a QCefView instance.
| QCefView (QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
| Constructs a QCefView instance.
| ~QCefView ()
| Destructs the QCefView instance.
void | addLocalFolderResource (const QString &path, const QString &url, int priority=0)
| Adds a url mapping item with local web resource directory.
void | addArchiveResource (const QString &path, const QString &url, const QString &password="", int priority=0)
| Adds a url mapping item with local archive (.zip) file which contains the web resource.
int | browserId ()
| Gets the browser id.
void | navigateToString (const QString &content)
| Navigates to the content.
void | navigateToUrl (const QString &url)
| Navigates to the URL.
bool | browserCanGoBack ()
| Checks whether the browser can go back.
bool | browserCanGoForward ()
| Checks whether the browser can go forward.
void | browserGoBack ()
| Requires the browser to go back.
void | browserGoForward ()
| Requires the browser to go forward.
bool | browserIsLoading ()
| Checks whether the browser is loading.
void | browserReload ()
| Requires the browser to reload.
void | browserStopLoad ()
| Requires the browser to stop load.
bool | triggerEvent (const QCefEvent &event)
| Triggers the event for main frame.
bool | triggerEvent (const QCefEvent &event, const QString &frameId)
| Triggers the event for specified frame.
bool | broadcastEvent (const QCefEvent &event)
| Broad cast the event for all frames.
bool | responseQCefQuery (const QCefQuery &query)
| Response the QCefQuery request.
bool | executeJavascript (const QString &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
bool | executeJavascriptWithResult (const QString &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.
bool | setPreference (const QString &name, const QVariant &value, const QString &error)
| Sets the preference for this browser.
void | setOSRFrameRate (int fps)
| Sets the frame rate for OSR (Off-Screen Rendering).
bool | hasDevTools ()
| Detects whether this browser has a devtools opened.
void | showDevTools ()
| Opens the devtools dialog.
void | closeDevTools ()
| Closes the devtools dialog.
void | setAllowDrag (bool allow)
| Sets whether dragging is allowed.
bool | allowDrag () const
| Indicates whether drag operations are allowed.
void | setZoomLevel (double level)
| Sets zoom level.
double | zoomLevel ()
| Get the zoom level value.
QVariant | inputMethodQuery (Qt::InputMethodQuery query) const override
| Please refer to QWidget::inputMethodQuery.

## Static Public Attributes
static const QString | MainFrameID
| The main frame identity.
static const QString | AllFrameID
| The identifier for all frames.

## Protected Member Functions
virtual QCefView * | onNewBrowser (const QString &sourceFrameId, const QString &url, const QString &name, QCefView::CefWindowOpenDisposition targetDisposition, QRect &rect, QCefSetting &settings)
| Gets called before a new browser created (only for browser created by non-JavaScript)
virtual bool | onNewPopup (const QString &frameId, const QString &targetUrl, QString &targetFrameName, QCefView::CefWindowOpenDisposition targetDisposition, QRect &rect, QCefSetting &settings, bool &disableJavascriptAccess)
| Gets called before the popup browser created (only for browser created by JavaScript)
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.
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.
virtual bool | onRequestCloseFromWeb ()
| Gets called on close request from web.
QPaintEngine * | paintEngine () const override
| Please refer to QWidget::paintEngine.
void | paintEvent (QPaintEvent *event) override
| Please refer to QWidget::paintEvent.
bool | event (QEvent *event) override

## Detailed Description

Represents the CEF browser view.

## Member Enumeration Documentation

## ◆ CefWindowOpenDisposition

enum QCefView::CefWindowOpenDisposition

Represents the CEF pop-up windows open disposition.

Enumerator
CefWindowOpenDispositionUnknown |
CefWindowOpenDispositionCurrentTab |
CefWindowOpenDispositionSingletonTab |
CefWindowOpenDispositionNewForeGroundTab |
CefWindowOpenDispositionNewBackgroundTab |
CefWindowOpenDispositionNewPopup |
CefWindowOpenDispositionNewWindow |
CefWindowOpenDispositionSaveToDisk |
CefWindowOpenDispositionOffTheRecord |
CefWindowOpenDispositionIgnoreAction |

## Constructor & Destructor Documentation

## ◆ QCefView() [1/2]

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

Constructs a QCefView instance.

Parameters

  url | The target url
  setting | The QCefSetting instance
  parent | The parent
  f | The Qt WindowFlags

## ◆ QCefView() [2/2]

QCefView::QCefView | ( | QWidget * | parent = nullptr,
|  | Qt::WindowFlags | f = Qt::WindowFlags() )

Constructs a QCefView instance.

Parameters

  parent | The parent
  f | The Qt WindowFlags

## ◆ ~QCefView()

QCefView::~QCefView | ( |  | ) |

Destructs the QCefView instance.

## Member Function Documentation

## ◆ addLocalFolderResource()

void QCefView::addLocalFolderResource | ( | const QString & | path,
|  | const QString & | url,
|  | int | priority = 0 )

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

## ◆ addArchiveResource()

void QCefView::addArchiveResource | ( | const QString & | path,
|  | const QString & | url,
|  | const QString & | password = "",
|  | int | priority = 0 )

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

## ◆ browserId()

int QCefView::browserId | ( |  | ) |

Gets the browser id.

Returns
  The browser id

## ◆ navigateToString()

void QCefView::navigateToString | ( | const QString & | content | ) |

Navigates to the content.

Parameters

  content | The content

## ◆ navigateToUrl()

void QCefView::navigateToUrl | ( | const QString & | url | ) |

Navigates to the URL.

Parameters

  url | The url

## ◆ browserCanGoBack()

bool QCefView::browserCanGoBack | ( |  | ) |

Checks whether the browser can go back.

Returns
  True if can; otherwise false

## ◆ browserCanGoForward()

bool QCefView::browserCanGoForward | ( |  | ) |

Checks whether the browser can go forward.

Returns
  True if can; otherwise false

## ◆ browserGoBack()

void QCefView::browserGoBack | ( |  | ) |

Requires the browser to go back.

## ◆ browserGoForward()

void QCefView::browserGoForward | ( |  | ) |

Requires the browser to go forward.

## ◆ browserIsLoading()

bool QCefView::browserIsLoading | ( |  | ) |

Checks whether the browser is loading.

Returns
  True if it is loading; otherwise false

## ◆ browserReload()

void QCefView::browserReload | ( |  | ) |

Requires the browser to reload.

## ◆ browserStopLoad()

void QCefView::browserStopLoad | ( |  | ) |

Requires the browser to stop load.

## ◆ triggerEvent() [1/2]

bool QCefView::triggerEvent | ( | const QCefEvent & | event | ) |

Triggers the event for main frame.

Parameters

  event | The QCefEvent instance

Returns
  True on successful; otherwise false

## ◆ triggerEvent() [2/2]

bool QCefView::triggerEvent | ( | const QCefEvent & | event,
|  | const QString & | frameId )

Triggers the event for specified frame.

Parameters

  event | The QCefEvent instance
  frameId | The frame id

Returns
  True on successful; otherwise false

## ◆ broadcastEvent()

bool QCefView::broadcastEvent | ( | const QCefEvent & | event | ) |

Broad cast the event for all frames.

Parameters

  event | The QCefEvent instance

Returns
  True on successful; otherwise false

## ◆ responseQCefQuery()

bool QCefView::responseQCefQuery | ( | const QCefQuery & | query | ) |

Response the QCefQuery request.

Parameters

  query | The query instance

Returns
  True on successful; otherwise false

## ◆ executeJavascript()

bool QCefView::executeJavascript | ( | const QString & | 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

## ◆ executeJavascriptWithResult()

bool QCefView::executeJavascriptWithResult | ( | const QString & | 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

## ◆ setPreference()

bool QCefView::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

## ◆ setOSRFrameRate()

void QCefView::setOSRFrameRate | ( | int | fps | ) |

Sets the frame rate for OSR (Off-Screen Rendering).

Parameters

  fps | The desired frame rate in frames per second.

## ◆ hasDevTools()

bool QCefView::hasDevTools | ( |  | ) |

Detects whether this browser has a devtools opened.

Returns
  True if opend already; otherwise false

## ◆ showDevTools()

void QCefView::showDevTools | ( |  | ) |

Opens the devtools dialog.

## ◆ closeDevTools()

void QCefView::closeDevTools | ( |  | ) |

Closes the devtools dialog.

## ◆ setAllowDrag()

void QCefView::setAllowDrag | ( | bool | allow | ) |

Sets whether dragging is allowed.

Parameters

  allow | True to allow dragging; false to disable it.

## ◆ allowDrag()

bool QCefView::allowDrag | ( |  | ) | const

Indicates whether drag operations are allowed.

Returns
  true if drag operations are permitted; otherwise, false.

## ◆ setZoomLevel()

void QCefView::setZoomLevel | ( | double | level | ) |

Sets zoom level.

Parameters

  level | The zoom level value.

## ◆ zoomLevel()

double QCefView::zoomLevel | ( |  | ) |

Get the zoom level value.

Returns
  the zoom level value.

## ◆ loadingStateChanged

void QCefView::loadingStateChanged | ( | const int & | browserId,
|  | bool | isLoading,
|  | bool | canGoBack,
|  | bool | canGoForward )
| signal

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

## ◆ loadStart

void QCefView::loadStart | ( | const int & | browserId,
|  | const QString & | frameId,
|  | bool | isMainFrame,
|  | int | transitionType )
| signal

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

## ◆ loadEnd

void QCefView::loadEnd | ( | const int & | browserId,
|  | const QString & | frameId,
|  | bool | isMainFrame,
|  | int | httpStatusCode )
| signal

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

## ◆ loadError

void QCefView::loadError | ( | const int & | browserId,
|  | const QString & | frameId,
|  | bool | isMainFrame,
|  | int | errorCode,
|  | const QString & | errorMsg,
|  | const QString & | failedUrl )
| signal

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

## ◆ draggableRegionChanged

void QCefView::draggableRegionChanged | ( | const QRegion & | draggableRegion,
|  | const QRegion & | nonDraggableRegion )
| signal

Gets called on draggable region changed.

Parameters

  draggableRegion | The new draggable region
  nonDraggableRegion | The new non-draggable region

## ◆ addressChanged

void QCefView::addressChanged | ( | const QString & | frameId,
|  | const QString & | url )
| signal

Gets called on the address changed.

Parameters

  frameId | The frame id
  url | The address

## ◆ titleChanged

void QCefView::titleChanged | ( | const QString & | title | ) |
| signal

Gets called on title changed.

Parameters

  title | The title

## ◆ faviconURLChanged

void QCefView::faviconURLChanged | ( | const QStringList & | urls | ) |
| signal

Gets called on favicon url changed.

Parameters

  urls | The urls

## ◆ fullscreenModeChanged

void QCefView::fullscreenModeChanged | ( | bool | fullscreen | ) |
| signal

Gets called on fullscreen mode changed.

Parameters

  fullscreen | The current fullscreen mode

## ◆ statusMessage

void QCefView::statusMessage | ( | const QString & | message | ) |
| signal

Gets called on status message changed.

Parameters

  message | The status message

## ◆ consoleMessage

void QCefView::consoleMessage | ( | const QString & | message,
|  | int | level )
| signal

Gets called on console message from the web content.

Parameters

  message | The message
  level | The level

## ◆ loadingProgressChanged

void QCefView::loadingProgressChanged | ( | double | progress | ) |
| signal

Gets called on loading progress changed.

Parameters

  progress | Current progress

## ◆ cefUrlRequest

void QCefView::cefUrlRequest | ( | const int & | browserId,
|  | const QString & | frameId,
|  | const QString & | url )
| signal

Gets called on built-in scheme URL access.

Parameters

  browserId | The browser id
  frameId | The frame id
  url | The full url

## ◆ cefQueryRequest

void QCefView::cefQueryRequest | ( | const int & | browserId,
|  | const QString & | frameId,
|  | const QCefQuery & | query )
| signal

Gets called on new QCefQuery request.

Parameters

  browserId | The browser id
  frameId | The frame id
  query | The query request

## ◆ invokeMethod

void QCefView::invokeMethod | ( | const int & | browserId,
|  | const QString & | frameId,
|  | const QString & | method,
|  | const QVariantList & | arguments )
| signal

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

## ◆ reportJavascriptResult

void QCefView::reportJavascriptResult | ( | const int & | browserId,
|  | const QString & | frameId,
|  | const QString & | context,
|  | const QVariant & | result )
| signal

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

## ◆ nativeBrowserCreated

void QCefView::nativeBrowserCreated | ( | QWindow * | window | ) |
| signal

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

Parameters

  window | The native browser windows

## ◆ onNewBrowser()

virtual QCefView * QCefView::onNewBrowser | ( | const QString & | sourceFrameId,
|  | const QString & | url,
|  | const QString & | name,
|  | QCefView::CefWindowOpenDisposition | targetDisposition,
|  | QRect & | rect,
|  | QCefSetting & | settings )
| protected virtual

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

Parameters

  sourceFrameId | 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

## ◆ onNewPopup()

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

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
  disableJavascriptAccess | The output value to receive the Javascript access switch

Returns
  True to cancel the popup; false to allow

## ◆ onNewDownloadItem()

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

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

## ◆ onUpdateDownloadItem()

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

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

## ◆ onRequestCloseFromWeb()

virtual bool QCefView::onRequestCloseFromWeb | ( |  | ) |
| protected virtual

Gets called on close request from web.

Returns
  True to allow the close, false to cancel the close

## ◆ inputMethodQuery()

QVariant QCefView::inputMethodQuery | ( | Qt::InputMethodQuery | query | ) | const
| override

Please refer to QWidget::inputMethodQuery.

## ◆ paintEngine()

QPaintEngine * QCefView::paintEngine | ( |  | ) | const
| override protected

Please refer to QWidget::paintEngine.

## ◆ paintEvent()

void QCefView::paintEvent | ( | QPaintEvent * | event | ) |
| override protected

Please refer to QWidget::paintEvent.

Parameters

  event |

## ◆ event()

bool QCefView::event | ( | QEvent * | event | ) |
| override protected

Parameters

  event |

Returns

## Member Data Documentation

## ◆ MainFrameID

const QString QCefView::MainFrameID
| static

The main frame identity.

## ◆ AllFrameID

const QString QCefView::AllFrameID
| static

The identifier for all frames.