Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How can i set baseUrl only once?
Forum Updated to NodeBB v4.3 + New Features

How can i set baseUrl only once?

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 265 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.
  • D Offline
    D Offline
    deleted256
    wrote on 11 Feb 2021, 17:26 last edited by
    #1

    I found the following code for rendering images from relative paths in HTML

    self.webPage.setHtml('<img src="image.png"/>', baseUrl=QUrl.fromLocalFile(os.getcwd()+os.path.sep))
    

    However i call setHTML a lot, and would rather be able to set baseURL once rather than adding it as an argument each time. How can i do this?

    1 Reply Last reply
    0
    • E Offline
      E Offline
      eyllanesc
      wrote on 12 Feb 2021, 00:27 last edited by
      #2

      You always have to set the baseUrl if you want to use setHtml, but if you want to repeat the code then create a method that does it:

      class Foo(Bar):
          def __init__(self, ...):
               super().__init(...)
               self._base_url = QUrl()
               self.base_url = QUrl.fromLocalFile(os.getcwd()+os.path.sep)
               self.webPage = ...
      
          @property
          def base_url(self):
              return self._base_url
      
          @base_url.setter
          def base_url(self, url):
              self._base_url = url
      
          def update_html(self, html):
              self.webPage.setHtml(html, self.base_url)
      

      then:

      self.update_html('<img src="image.png"/>');
      

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      0

      1/2

      11 Feb 2021, 17:26

      • Login

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