diff options
Diffstat (limited to 'examples')
3 files changed, 23 insertions, 21 deletions
diff --git a/examples/webengine/quicknanobrowser/BrowserWindow.qml b/examples/webengine/quicknanobrowser/BrowserWindow.qml index f3bd8e457..be1e42c73 100644 --- a/examples/webengine/quicknanobrowser/BrowserWindow.qml +++ b/examples/webengine/quicknanobrowser/BrowserWindow.qml @@ -487,7 +487,7 @@ ApplicationWindow { id: devToolsView visible: devToolsEnabled.checked height: 400 - inspectedView: tabs.currentIndex < tabs.count ? tabs.getTab(tabs.currentIndex).item : null + inspectedView: visible && tabs.currentIndex < tabs.count ? tabs.getTab(tabs.currentIndex).item : null anchors.left: parent.left anchors.right: parent.right anchors.bottom: parent.bottom diff --git a/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc b/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc index 4f44d9f6c..4b39463b6 100644 --- a/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc +++ b/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc @@ -184,16 +184,18 @@ \section2 Adding Context Menu Items - We add menu items to the context menu, so that users can right-click a link - to have it opened in the same tab, a new window, or a new tab. We override - QWebEngineView::contextMenuEvent and use + We add a menu item to the context menu, so that users can right-click to have an inspector + opened in a new window. We override QWebEngineView::contextMenuEvent and use QWebEnginePage::createStandardContextMenu to create a default QMenu with a default list of QWebEnginePage::WebAction actions. - The default name for QWebEnginePage::OpenLinkInThisWindow action is - \uicontrol Follow. For clarity, we rename it - \uicontrol {Open Link in This Tab}. Also, we add the actions for opening - links in a separate window or in a new tab: + The default name for QWebEnginePage::InspectElement action is + \uicontrol Inspect. For clarity, we rename it to \uicontrol {Open Inspector In New Window} when + there is no Inspector present yet, + and \uicontrol {Inspect Element} when it's already created. + + We also check if the QWebEnginePage::ViewSource action is in the menu, because if it's not + we have to add a separator as well. \quotefromfile webenginewidgets/simplebrowser/webview.cpp \skipto WebView::contextMenuEvent( diff --git a/examples/webenginewidgets/simplebrowser/webview.cpp b/examples/webenginewidgets/simplebrowser/webview.cpp index ab42c4a0a..fcbb543f2 100644 --- a/examples/webenginewidgets/simplebrowser/webview.cpp +++ b/examples/webenginewidgets/simplebrowser/webview.cpp @@ -177,21 +177,21 @@ QWebEngineView *WebView::createWindow(QWebEnginePage::WebWindowType type) void WebView::contextMenuEvent(QContextMenuEvent *event) { QMenu *menu = page()->createStandardContextMenu(); - const QList<QAction*> actions = menu->actions(); - auto it = std::find(actions.cbegin(), actions.cend(), page()->action(QWebEnginePage::OpenLinkInThisWindow)); - if (it != actions.cend()) { - (*it)->setText(tr("Open Link in This Tab")); - ++it; - QAction *before(it == actions.cend() ? nullptr : *it); - menu->insertAction(before, page()->action(QWebEnginePage::OpenLinkInNewWindow)); - menu->insertAction(before, page()->action(QWebEnginePage::OpenLinkInNewTab)); - } - it = std::find(actions.cbegin(), actions.cend(), page()->action(QWebEnginePage::InspectElement)); - if (it == actions.cend()) { + const QList<QAction *> actions = menu->actions(); + auto inspectElement = std::find(actions.cbegin(), actions.cend(), page()->action(QWebEnginePage::InspectElement)); + if (inspectElement == actions.cend()) { + auto viewSource = std::find(actions.cbegin(), actions.cend(), page()->action(QWebEnginePage::ViewSource)); + if (viewSource == actions.cend()) + menu->addSeparator(); + QAction *action = new QAction(menu); - action->setText("Inspect Element"); + action->setText("Open inspector in new window"); connect(action, &QAction::triggered, [this]() { emit devToolsRequested(page()); }); - menu->addAction(action); + + QAction *before(inspectElement == actions.cend() ? nullptr : *inspectElement); + menu->insertAction(before, action); + } else { + (*inspectElement)->setText(tr("Inspect element")); } menu->popup(event->globalPos()); } |