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] How to show image in html file with QTextBrowser?
QtWS25 Last Chance

[Solved] How to show image in html file with QTextBrowser?

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 12.9k Views
  • 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.
  • Z Offline
    Z Offline
    zither
    wrote on last edited by
    #1

    Dear all,

    I would like to load a html file which contains
    < img src="http://www.test.com/image........>
    image link.

    How can I show that image in QTextBrowser? It just show only unknown images...

    Thanks

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      QTextBrowser only works for local files. It has no support for downloading resources from the network. If you need that, a QWebView instance would be the widget to choose.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zither
        wrote on last edited by
        #3

        Can I download the image resource to local link & use them? How can it be?

        I don't want to use QWebView because it'll need QWebKit module which is heavy module.

        Thanks

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          If you download the image to the local file system you would need to modify the HTML source to point to this files instead of web URLs. It's doable, but for me, this would be too awkward and error prone, I'd go with webkit.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            zither
            wrote on last edited by
            #5

            I try with this implementation, but not work.
            What's wrong with that..?

            @QVariant TextBrowser::loadResource(int type, const QUrl &name)
            {
            if (type == QTextDocument::ImageResource){
            QFile file(srcUrl.resolved(name).toLocalFile());
            if (file.open(QIODevice::ReadOnly))
            return file.readAll();
            }
            return QTextBrowser::loadResource(type,name);
            }@

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jjoe
              wrote on last edited by
              #6

              This is my implementation for QTextDocument it should work for QTextBrowser too.
              @ QVariant loadResource(int type, const QUrl &name)
              {
              if (type == QTextDocument::ImageResource)
              {
              return QImage(name.toLocalFile());
              }
              return QTextDocument::loadResource(type, name);
              }@

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                zither
                wrote on last edited by
                #7

                Thanks for your reply,

                When I change like that, I got error msg in console
                @QColor::setNamedColor: Unknown color name 'inherit'@
                Previously, I got can't get file error.

                Is this error due to QImage Plugins?

                Thanks

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  jjoe
                  wrote on last edited by
                  #8

                  This is strange because this function does not need anything from QColor. Missing QImage plugins are not interrupting the build process. Maybe a missing include? I have just this one: @#include <QtGui>@

                  Appears this message during the program run or when you try to build the binary?

                  1 Reply Last reply
                  0
                  • Z Offline
                    Z Offline
                    zither
                    wrote on last edited by
                    #9

                    Thanks

                    I already include QtGui, but not work. It appears in debug console when that function is called.

                    I think that might be bug. I'll make separate post for that..

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      goetz
                      wrote on last edited by
                      #10

                      The anser has been given in the "new thread on that error":http://developer.qt.nokia.com/forums/viewthread/9997. Please discuss the error specific topics over there.

                      http://www.catb.org/~esr/faqs/smart-questions.html

                      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