I have a simple widget that is a QWebView. I load it using setHtml (). In most cases, it’s just that the user can read the stylized text, however there are several links, and if they click on it, QWebView correctly displays the linked page, but now there is no way to return to the original page. I want to implement the back key combination (or, maybe the back button, but the problem is the same). And I cannot figure out how to say my QWebView or its QWebPage for this. Some code tries everything I can think of:
class helpDisplay(QWebView): def __init__(self, parent=None ): super(helpDisplay, self).__init__(parent) self.backAction = self.page().action(QWebPage.Back) self.backAction.setEnabled(True)
None of this causes navigation backward through the link. Beat ctl- [does nothing. Pressing b enters the keyPressEvent trap and triggers triggerAction and is activated, but nothing happens.
Edit: found WebPage.history () and added the following to the key-b trap: self.page (). History(). back () This view works: if I click start-> A, self.page().history().canGoBack() is False and self.page().history().back() does nothing. However, if I click another start-> A-> B link, now it can GoBack () and return to page A. But I can’t go back to the original page loaded with setHtml ().
Conclusion: WebView.setHtml () does not create an entry in WebPage.history. This may explain why backAction is not working ...
Further editing: after working in Qt Assistant, I found that under QWebFrame.setHtml () it admits: "Note: this method will not affect the session or global history ..." Unfortunately, they did not carry this QWebPage or QWebView note. Actually, this makes sense: a story item will usually just be a URL, so it’s not too weird that they don’t want to store 20K or 50K html text as a story item.
source share