[SOLVED] A png image within HTML code in a QTextEdit
-
wrote on 5 Jun 2015, 09:05 last edited by sirop 6 May 2015, 10:33
Hallo.
I have a rather simple piece of code which works until I try to use an <img> html tag:
theorie = new QWidget(); theorie->setLayout(new QGridLayout); QTextEdit* theorieText= new QTextEdit(readHTML("html\\theory.html")); theorieText->setReadOnly(true); theorie->layout()->addWidget(theorieText);
The Html file is also rather simple:
<html> <head> <title></title> </head> <body> <h2> TEST <img src='images\\Diagramm-mit-Dehngrenzen.png' height='90' width='80'/> </h2> </body> </html>
The html file can be loaded into the QTextEdit widget, but the png image is not shown.
What am I doing wrong?
-
Hallo.
I have a rather simple piece of code which works until I try to use an <img> html tag:
theorie = new QWidget(); theorie->setLayout(new QGridLayout); QTextEdit* theorieText= new QTextEdit(readHTML("html\\theory.html")); theorieText->setReadOnly(true); theorie->layout()->addWidget(theorieText);
The Html file is also rather simple:
<html> <head> <title></title> </head> <body> <h2> TEST <img src='images\\Diagramm-mit-Dehngrenzen.png' height='90' width='80'/> </h2> </body> </html>
The html file can be loaded into the QTextEdit widget, but the png image is not shown.
What am I doing wrong?
@sirop Where is this png file present ?
-
wrote on 5 Jun 2015, 09:31 last edited by
-
@sirop Try
images/Diagramm-mit-Dehngrenzen.png
instead. Note the slash. -
wrote on 5 Jun 2015, 09:50 last edited by
The paths in URLs should use forward not backslashes (and backslashes do not need escaping here).
The relative path will be relative to the current working directory of the running process. This is quite unlikely to be where the source code is (esp. if you are shadow building).
In general you can use / everywhere in Qt APIs and save yourself some backtick-itus like in the readHTML() call.
-
@sirop Where ? I don't see that post. Try posting again.
-
The paths in URLs should use forward not backslashes (and backslashes do not need escaping here).
The relative path will be relative to the current working directory of the running process. This is quite unlikely to be where the source code is (esp. if you are shadow building).
In general you can use / everywhere in Qt APIs and save yourself some backtick-itus like in the readHTML() call.
wrote on 5 Jun 2015, 10:32 last edited by sirop 6 May 2015, 10:34@ChrisW67 said:
The relative path will be relative to the current working directory of the running process. This is >quite unlikely to be where the source code is (esp. if you are shadow building).
Your hint is almost right. Of course, I use the build and not the source directory.
The point is that QTextEdit understands the image path within the HTML file also only if the image path is relative to the working dir of the running process and not to the directory of the HTML file.
So now my HTML file looks like:<html> <head> <title></title> </head> <body> <h2> TEST <img src='html\images\Diagramm-mit-Dehngrenzen.png' height='480' width='480'> </h2> </body> </html>
Which slashes -- forward or backward -- I use, does not matter.
However, now neither firefox nor opera show the image as you can understand.
7/8