[Gambas-user] WebView - How to show images?

Martin Belmonte mbelmonte at belmotek.net
Thu Feb 17 10:55:10 CET 2022


El 16/2/22 a las 22:11, vuott--- via User escribió:
> Fabien's suggestion works for me;  but it works using QT, not by using GTK.
In my case it has not worked for any of the following components:
gb.gui + gb.gui.webview
gb.qt5 + gb.qt5.webview

This code is for test:

Private sWebForeground As String
Private sWebBackground As String

Public Sub Form_Open()
   Dim sContent As String
   ' I use this image file
   '"wget 
https://upload.wikimedia.org/wikipedia/commons/0/0d/Asymmetricwave2.png"

   sWebForeground = "#" & Hex(Color.Foreground, 6)
   sWebBackground = "#" & Hex(Color.Background, 6)

   sContent = "<html><head></head><body style=\"color:" & sWebForeground 
& "; background-color:" & sWebBackground & "; word-wrap: break-word; 
-webkit-nbsp-mode: space; -webkit-line-break: after-white-space;\">\n"
   sContent &= File.Load("./content.txt")
   sContent &= "</body></html>"

   WebView1.SetHtml(sContent)

End

then content.txt content is:

<h2>Electron</h2>
<p>The electron is a subatomic ...</p>
<img width="400" alt="test" src="/tmp/Asymmetricwave2.png"></img>

Regards.


More information about the User mailing list