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] display an image in textEdit
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] display an image in textEdit

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 10.9k 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.
  • G Offline
    G Offline
    goetz
    wrote on last edited by
    #2

    You will have to make an HTML with <img> tag.

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

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kalster
      wrote on last edited by
      #3

      can i have an example please because i do not see an image method for textEdit?

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

        It's just ordinary HTML:

        @
        <html>
        <body>
        There is a an image after this word <img src="/path/to/image" />.
        </body>
        </html>
        @

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

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kalster
          wrote on last edited by
          #5

          wow that's easy. thank you Volker

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kalster
            wrote on last edited by
            #6

            how to write the image path so that the image loads on other OS. I need one line of code to be compatible on mac, linux and windows. is this possible?

            I guess what i need to know is how to get the absolute path to my program?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              alexisdm
              wrote on last edited by
              #7

              You can get the path to your executable with "QApplication::applicationDirPath()":http://developer.qt.nokia.com/doc/qt-4.7/qcoreapplication.html#id-69a34508-b7ba-4b8f-9230-69019ffcb976

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kalster
                wrote on last edited by
                #8

                path information for the image.

                @ui->textEdit->setHtml("<img src="+ QApplication::
                applicationDirPath() + "/images.gif>");@

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  alexisdm
                  wrote on last edited by
                  #9

                  What is that code supposed to do ?

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    kalster
                    wrote on last edited by
                    #10

                    display an image inside of the textEdit and getting the image from the correct file path. the file path will output where your exe is located.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      alexisdm
                      wrote on last edited by
                      #11

                      Try something like that:
                      @QString imagePath = QApplication::applicationDirPath() + "/image.png";
                      QString html = QString("<img src="%1" />").arg(imagePath);
                      ui->textEdit->setHtml(html);@
                      with the image in the same directory as your executable (don't forget the "/" at the beginning of your relative, since applicationDirPath() doesn't have one at its end).

                      Edit: you have to use &lt; and &gt; to display < and > in your post :)

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        kalster
                        wrote on last edited by
                        #12

                        thank you alexisdm. I fixed the code in my previous post

                        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