Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] A png image within HTML code in a QTextEdit
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
qtexteditimagehtml
8 Posts 3 Posters 8.6k Views 2 Watching
  • 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.
  • S Offline
    S Offline
    sirop
    wrote on 5 Jun 2015, 09:05 last edited by sirop 6 May 2015, 10:33
    #1

    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?

    To be, or not to be: that is the question:
    Whether ’tis nobler in the mind to suffer
    The slings and arrows of outrageous fortune,
    Or to take arms against a sea of troubles,
    And by opposing end them?

    P 1 Reply Last reply 5 Jun 2015, 09:18
    0
    • S sirop
      5 Jun 2015, 09:05

      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?

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 5 Jun 2015, 09:18 last edited by
      #2

      @sirop Where is this png file present ?

      157

      S 1 Reply Last reply 5 Jun 2015, 09:31
      0
      • P p3c0
        5 Jun 2015, 09:18

        @sirop Where is this png file present ?

        S Offline
        S Offline
        sirop
        wrote on 5 Jun 2015, 09:31 last edited by
        #3

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

        To be, or not to be: that is the question:
        Whether ’tis nobler in the mind to suffer
        The slings and arrows of outrageous fortune,
        Or to take arms against a sea of troubles,
        And by opposing end them?

        P 1 Reply Last reply 5 Jun 2015, 09:47
        0
        • S sirop
          5 Jun 2015, 09:31

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

          P Offline
          P Offline
          p3c0
          Moderators
          wrote on 5 Jun 2015, 09:47 last edited by
          #4

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

          157

          S 1 Reply Last reply 5 Jun 2015, 10:25
          1
          • C Offline
            C Offline
            ChrisW67
            wrote on 5 Jun 2015, 09:50 last edited by
            #5

            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.

            S 1 Reply Last reply 5 Jun 2015, 10:32
            1
            • P p3c0
              5 Jun 2015, 09:47

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

              S Offline
              S Offline
              sirop
              wrote on 5 Jun 2015, 10:25 last edited by
              #6

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

              To be, or not to be: that is the question:
              Whether ’tis nobler in the mind to suffer
              The slings and arrows of outrageous fortune,
              Or to take arms against a sea of troubles,
              And by opposing end them?

              P 1 Reply Last reply 5 Jun 2015, 10:28
              0
              • S sirop
                5 Jun 2015, 10:25

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

                P Offline
                P Offline
                p3c0
                Moderators
                wrote on 5 Jun 2015, 10:28 last edited by
                #7

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

                157

                1 Reply Last reply
                0
                • C ChrisW67
                  5 Jun 2015, 09:50

                  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.

                  S Offline
                  S Offline
                  sirop
                  wrote on 5 Jun 2015, 10:32 last edited by sirop 6 May 2015, 10:34
                  #8

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

                  To be, or not to be: that is the question:
                  Whether ’tis nobler in the mind to suffer
                  The slings and arrows of outrageous fortune,
                  Or to take arms against a sea of troubles,
                  And by opposing end them?

                  1 Reply Last reply
                  0

                  1/8

                  5 Jun 2015, 09:05

                  • Login

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