[SOLVED] A png image within HTML code in a QTextEdit



  • 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?


  • Moderators

    @sirop Where is this png file present ?



  • @p3c0 said:

    @sirop Where is this png file present ?

    It is in the subfolder 'images' . :)

    I checked this html file with both firefox and opera. The png image is displayed in both browsers.
    But my QTextEdit widget shows only a kind of placeholder instead of the image.


  • Moderators

    @sirop Try images/Diagramm-mit-Dehngrenzen.png instead. Note the slash.



  • 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.



  • @p3c0 said:

    @sirop Try images/Diagramm-mit-Dehngrenzen.png instead. Note the slash.

    @p3c0

    No, this was not the problem or the answer to the problem.
    See my answer to @ChrisW67 .


  • Moderators

    @sirop Where ? I don't see that post. Try posting again.



  • @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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.