diff --git a/src/plugins/help/helpplugin.cpp b/src/plugins/help/helpplugin.cpp index e4ff85fe253..d78cbaa2b85 100644 --- a/src/plugins/help/helpplugin.cpp +++ b/src/plugins/help/helpplugin.cpp @@ -593,14 +593,9 @@ void HelpPlugin::showContextHelp() .arg(contextHelpId) .arg(creatorTheme()->color(Theme::TextColorNormal).name())); } else { - const QUrl &oldSource = viewer->source(); - if (source != oldSource) { - viewer->stop(); - viewer->setSource(source); // triggers loadFinished which triggers id highlighting - } else { - viewer->scrollToAnchor(source.fragment()); - } viewer->setFocus(); + viewer->stop(); + viewer->setSource(source); // triggers loadFinished which triggers id highlighting ICore::raiseWindow(viewer); } } diff --git a/src/plugins/help/helpviewer.h b/src/plugins/help/helpviewer.h index 93af29554f3..e1f52de8336 100644 --- a/src/plugins/help/helpviewer.h +++ b/src/plugins/help/helpviewer.h @@ -57,7 +57,6 @@ public: virtual QUrl source() const = 0; // metacall in HelpPlugin::updateSideBarSource Q_INVOKABLE virtual void setSource(const QUrl &url) = 0; - virtual void scrollToAnchor(const QString &anchor) = 0; virtual void highlightId(const QString &id) { Q_UNUSED(id) } virtual void setHtml(const QString &html) = 0; diff --git a/src/plugins/help/qtwebkithelpviewer.cpp b/src/plugins/help/qtwebkithelpviewer.cpp index e517ea1d5f9..a9ce4ed4c6f 100644 --- a/src/plugins/help/qtwebkithelpviewer.cpp +++ b/src/plugins/help/qtwebkithelpviewer.cpp @@ -467,16 +467,12 @@ void QtWebKitHelpViewer::setSource(const QUrl &url) QUrl newWithoutFragment = url; newWithoutFragment.setFragment(QString()); if (oldWithoutFragment == newWithoutFragment) { + m_webView->page()->mainFrame()->scrollToAnchor(url.fragment()); slotLoadStarted(); slotLoadFinished(); } } -void QtWebKitHelpViewer::scrollToAnchor(const QString &anchor) -{ - m_webView->page()->mainFrame()->scrollToAnchor(anchor); -} - void QtWebKitHelpViewer::highlightId(const QString &id) { if (m_oldHighlightId == id) diff --git a/src/plugins/help/qtwebkithelpviewer.h b/src/plugins/help/qtwebkithelpviewer.h index 2cc93c0aec5..2e2b94503b3 100644 --- a/src/plugins/help/qtwebkithelpviewer.h +++ b/src/plugins/help/qtwebkithelpviewer.h @@ -56,7 +56,6 @@ public: QUrl source() const; void setSource(const QUrl &url); - void scrollToAnchor(const QString &anchor); void highlightId(const QString &id); void setHtml(const QString &html); diff --git a/src/plugins/help/textbrowserhelpviewer.cpp b/src/plugins/help/textbrowserhelpviewer.cpp index 882beccc289..531cfa5c454 100644 --- a/src/plugins/help/textbrowserhelpviewer.cpp +++ b/src/plugins/help/textbrowserhelpviewer.cpp @@ -38,6 +38,8 @@ #include #include #include +#include +#include #include #include @@ -145,12 +147,13 @@ void TextBrowserHelpViewer::setSource(const QUrl &url) slotLoadStarted(); m_textBrowser->setSource(url); - slotLoadFinished(); -} - -void TextBrowserHelpViewer::scrollToAnchor(const QString &anchor) -{ - m_textBrowser->scrollToAnchor(anchor); + QTimer::singleShot(0, this, [this, url]() { + if (!url.fragment().isEmpty()) + m_textBrowser->scrollToAnchor(url.fragment()); + if (QScrollBar *hScrollBar = m_textBrowser->horizontalScrollBar()) + hScrollBar->setValue(0); + slotLoadFinished(); + }); } void TextBrowserHelpViewer::setHtml(const QString &html) diff --git a/src/plugins/help/textbrowserhelpviewer.h b/src/plugins/help/textbrowserhelpviewer.h index bc332b24e6c..d71bf2b5ef8 100644 --- a/src/plugins/help/textbrowserhelpviewer.h +++ b/src/plugins/help/textbrowserhelpviewer.h @@ -55,7 +55,6 @@ public: QUrl source() const; void setSource(const QUrl &url); - void scrollToAnchor(const QString &anchor); void setHtml(const QString &html);