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. QTextBrowser HTML document images have bad resolution
Forum Updated to NodeBB v4.3 + New Features

QTextBrowser HTML document images have bad resolution

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 2 Posters 1.5k Views 1 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.
  • P Offline
    P Offline
    Pietroro
    wrote on last edited by
    #5

    Sure, here is the html:

    <!DOCTYPE html>
    <html>
        <body style="margin: 50px;" >
            <h1 style="text-align:center;"> Arbitrary Magnetic Fields with a CSV File</h1>
            <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
                <br/>
                <img style="display: block; margin-left: auto; margin-right: auto;" src="example_field_math.png" height="150">
            </p>
        </body>
    </html>
    

    The image (example_field_math.png) I'm using is the following: example_field_math.png

    And here are two rendered views, once in browser where everything works out well, another inside QT.
    Browser:
    Screenshot from 2021-01-04 15-51-03.png
    QT:
    Screenshot from 2021-01-04 15-50-37.png

    1 Reply Last reply
    1
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #6

      Hi
      Super. Hmm yes that really looks bad.

      Where do i place the .png so it can find it ?
      In a Qressource file or ?
      (sorry not used TextBroser much)

      P 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        Super. Hmm yes that really looks bad.

        Where do i place the .png so it can find it ?
        In a Qressource file or ?
        (sorry not used TextBroser much)

        P Offline
        P Offline
        Pietroro
        wrote on last edited by
        #7

        @mrjj no worries, me neither :D

        I placed it in the same directory as my html file. However I had to make sure that the directory is included in the paths searched for resources by the textbrowser. The docs say that the path leading to the directory containing the html is included by default. In my experience however that is not the case. I used the following to include the path manually:

           QStringList list = textbrowser->searchPaths();
           if(list.empty()) { list.append(QString::fromStdString("/absolute/path/to/directory/")); }
           textbrowser->setSearchPaths(list);
        

        Hope this helps

        mrjjM 1 Reply Last reply
        1
        • P Pietroro

          @mrjj no worries, me neither :D

          I placed it in the same directory as my html file. However I had to make sure that the directory is included in the paths searched for resources by the textbrowser. The docs say that the path leading to the directory containing the html is included by default. In my experience however that is not the case. I used the following to include the path manually:

             QStringList list = textbrowser->searchPaths();
             if(list.empty()) { list.append(QString::fromStdString("/absolute/path/to/directory/")); }
             textbrowser->setSearchPaths(list);
          

          Hope this helps

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #8

          @Pietroro
          Worked perfectly :)
          I just pointed it to the project folder.

          I get the same bad-looking image in Qt 5.15.1 so I doubt they fixed it.

          Looking around in
          https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qtextbrowser.cpp.html

          to see if i can spot what actually does the scaling.

          P 1 Reply Last reply
          2
          • mrjjM mrjj

            @Pietroro
            Worked perfectly :)
            I just pointed it to the project folder.

            I get the same bad-looking image in Qt 5.15.1 so I doubt they fixed it.

            Looking around in
            https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qtextbrowser.cpp.html

            to see if i can spot what actually does the scaling.

            P Offline
            P Offline
            Pietroro
            wrote on last edited by
            #9

            Hi @mrjj

            has any progress been made on your end? I tried to follow along in the file you linked yesterday, I could follow up to here. To me it seems like the <img> tag is serialised (or converted into text?) and inserted into the document. I can also see how the width and height properties of the "QTextImageFormat" are set, but I have unfortunately lost track of those. That is to say that I have no clue where they show up again.

            Thanks for your help

            mrjjM 1 Reply Last reply
            0
            • P Pietroro

              Hi @mrjj

              has any progress been made on your end? I tried to follow along in the file you linked yesterday, I could follow up to here. To me it seems like the <img> tag is serialised (or converted into text?) and inserted into the document. I can also see how the width and height properties of the "QTextImageFormat" are set, but I have unfortunately lost track of those. That is to say that I have no clue where they show up again.

              Thanks for your help

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #10

              @Pietroro
              Hi
              Well i ended up with QTextDocument/Fragment and QWidgetTextControl too but
              Its all wrapped in private pointers so its very doubtful we can replace enough to make it scale better.

              However, a fun test could be to override the QBrowser Paint event and see if changes to QPainter is
              carried through the call stack as you might then be able to allow better scale.

              1 Reply Last reply
              1
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #11

                Hi
                I tried to overwrite the paint event but too much is hidden in private classes so
                it was not really possible.
                I also tried
                virtual void initPainter(QPainter *painter) const override
                to see if i could affect the painter but nothing.

                I also tried using SVG file and to my surprise it also became ugly.

                So sadly it seems it's not fixable with inheritance.

                P 1 Reply Last reply
                1
                • mrjjM mrjj

                  Hi
                  I tried to overwrite the paint event but too much is hidden in private classes so
                  it was not really possible.
                  I also tried
                  virtual void initPainter(QPainter *painter) const override
                  to see if i could affect the painter but nothing.

                  I also tried using SVG file and to my surprise it also became ugly.

                  So sadly it seems it's not fixable with inheritance.

                  P Offline
                  P Offline
                  Pietroro
                  wrote on last edited by
                  #12

                  @mrjj Thanks for all the help you have been providing. Is this considered to be a bug then?

                  I have read somewhere that the issue might lie in the TextBrowser not being able to do any anti aliasing, that would sort of explain why even SVGs are affected. But if that's the case it is not going to be easily fixable...

                  What is usually the procedure to report these kinds of bugs?

                  mrjjM 1 Reply Last reply
                  0
                  • P Pietroro

                    @mrjj Thanks for all the help you have been providing. Is this considered to be a bug then?

                    I have read somewhere that the issue might lie in the TextBrowser not being able to do any anti aliasing, that would sort of explain why even SVGs are affected. But if that's the case it is not going to be easily fixable...

                    What is usually the procedure to report these kinds of bugs?

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #13

                    @Pietroro

                    Well im not sure its a bug as such, more like a design choice favoring speed over fidelity but nobody will
                    be angry about opening a feature enhancement ticket.

                    Regarding the use of SVG. it clearly rasters the SVG before drawing it so hence we got no benefit of it being vector.

                    Go to
                    https://bugreports.qt.io/secure/Dashboard.jspa
                    and login with the same info as you use here.

                    Then open a ticket. Make sure to provide details about Qt version and
                    attach a zip file containing a runnable project the demonstrates this so
                    it's easy for them to reproduce.

                    and then come back here and post link to ticket so others can vote for it.

                    But they are quite busy with Qt 6 so I highly doubt e see any fix to older versions any time soon.

                    1 Reply Last reply
                    1
                    • P Offline
                      P Offline
                      Pietroro
                      wrote on last edited by
                      #14

                      Here we go, along with a poorly written minumum runnable project.

                      QTBUG-89843

                      1 Reply Last reply
                      0

                      • Login

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