Overview
TheZeal::Browser::WebView class is a customized Qt WebEngineView widget that provides enhanced functionality for displaying documentation content. It extends the standard QWebEngineView with zoom controls, custom context menus, and special handling for mouse and wheel events.
Header: src/libs/browser/webview.h
Inherits: QWebEngineView
Class Definition
Constructor
WebView()
- Initializes a custom WebPage instance
- Sets zoom level to default (100%)
- Enables PDF plugin support via
QWebEngineSettings::PluginsEnabled - Disables focus on navigation via
QWebEngineSettings::FocusOnNavigationEnabled - Installs a global event filter for handling mouse and wheel events
parent- Parent QWidget (optional)
Zoom Management
zoomLevel()
setZoomLevel()
level- Zoom level index (clamped to valid range)
- Clamps the level to valid range:
[0, availableZoomLevels().size() - 1] - Scales zoom factor for HiDPI displays (>96 DPI)
- Emits
zoomLevelChanged()signal when changed
availableZoomLevels()
{30, 40, 50, 67, 80, 90, 100, 110, 120, 133, 150, 170, 200, 220, 233, 250, 270, 285, 300}
defaultZoomLevel()
Zoom Slots
zoomIn()
zoomOut()
resetZoom()
Signals
zoomLevelChanged()
Event Handling
The WebView provides custom handling for several events:Mouse Button Events
- Back Button: Navigates to the previous page in history
- Forward Button: Navigates to the next page in history
Wheel Events
- Ctrl + Mouse Wheel: Adjusts zoom level (every 120 units of wheel delta changes zoom by one level)
Context Menu
Provides a custom context menu with options:- On Links: Open in new tab, open in desktop browser, copy link
- On Selection: Copy selected text
- On Page: Back, forward, open in desktop browser
qrc:// for local resources, javascript: for scripts).
Qt WebEngine Integration
The WebView class leverages Qt WebEngine for modern web rendering:Enabled Features
- PDF Support: Plugins are enabled to support embedded PDF viewing
- Custom Navigation: Uses custom WebPage for navigation control
- HiDPI Scaling: Automatic zoom adjustment for high-DPI displays
Window Creation
Usage Example
Implementation Details
Source Files
- Header: src/libs/browser/webview.h
- Implementation: src/libs/browser/webview.cpp
Key Implementation Notes
-
DPI Scaling (webview.cpp:68): Zoom factor calculation includes DPI compensation:
- Event Filtering (webview.cpp:244): Uses event filter on application instance to intercept mouse and wheel events on child widgets
- Context Menu (webview.cpp:109): Dynamically builds context menu based on the clicked element type and URL scheme
See Also
- WebPage - Custom page class used by WebView
- WebBridge - JavaScript bridge for C++ communication
- Qt WebEngineView Documentation