Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. Custom error pages (404, 403 etc) and setHtml

Custom error pages (404, 403 etc) and setHtml

Scheduled Pinned Locked Moved Unsolved QtWebEngine
2 Posts 1 Posters 927 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Harborman
    wrote on last edited by
    #1

    I'm in PyQt5. How do I set my own error pages for QWebEngine, like when the page is not found or it's forbidden? I'd like a different error page for every error.
    I read this but it didn't help at all:
    https://stackoverflow.com/questions/51656117/how-to-get-http-status-codes-from-qt-qwebengineview/53516333#53516333

    Also, I'm thinking of replacing the error pages with custom html that's hardcoded into the source code like this:

    self.tabs.currentWidget().setHtml("Bad syntax<br>You have to start your address with 'http'.")
    

    But I have a problem with this setHtml method. It automatically puts this in the url bar (lineEdit):
    "data:text/html;charset=UTF-8,Bad syntax%3Cbr%3EYou have to start your address with %27http%27."
    How do I stop this from happening and instead retain what user wrote on the url bar? Of course I tried urlbar.setText, but it's somehow ignored in this case, unless load the page twice.

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Harborman
      wrote on last edited by
      #2

      I worked around the urlbar text thing with this.

              if url.startswith("data:"):
                  text = self.urlbar.text()
                  self.urlbar.setText(text)
      

      It basically works, because setHtml always forces something starting with "data:" into the urlbar.

      As far as the custom Html status codes / error messages, I can make a custom 404.html page on my Apache server and direct my .htaccess file to it, but that's how far I can go.
      Is there any "onLoadFailed" type of syntax in PyQt where I could check if a page was able to be loaded at all? I've disabled Chromium's status codes with this:

              settings = QWebEngineSettings.globalSettings()
              settings.setAttribute(QWebEngineSettings.ErrorPageEnabled, False)
      

      but if a page is offline for example, all I get is a blank page which is confusing to users.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved