Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Strange behaviour of QTextCursor.insertImage() within a loop
Forum Updated to NodeBB v4.3 + New Features

Strange behaviour of QTextCursor.insertImage() within a loop

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
14 Posts 4 Posters 1.8k 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.
  • F Offline
    F Offline
    fmoerl
    wrote on last edited by fmoerl
    #5

    I try to build a table of 3 columns, the number of lines is variable, that's why i use the for-loop. The first column shows just one line of text, the second column gives more text with line breaks. The third column should show a picture. sp1, sp2 and sp3 are of type QStringList and include the information to show, sp3 includes the paths to the pictures.

    When doing it that way, only the last picture is shown in the third column of the first line. The text in the other cells works fine.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #6

      So if you just put the path to the image in the last column rather than the image, what do you get ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fmoerl
        wrote on last edited by
        #7

        If you mean simply the text of the path, that's what i tested too and is given in my example above. The path (text) is written in each cell and differs in each cell.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #8

          Can you provide a complete example that shows that behaviour ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • F Offline
            F Offline
            fmoerl
            wrote on last edited by
            #9

            My example given above should include all information. The for-loop iterates the number of elements in sp1 (first column), sp2 (second column) and sp3 (third column, includes paths to images) the same size. Whereas I can fill some QStringList's with phrases, the path to images on your computer is unknown to me. When I can provide other information, please ask.

            1 Reply Last reply
            0
            • F Offline
              F Offline
              fmoerl
              wrote on last edited by
              #10

              Here is an example of the output, a *.odf-file (in german) including a table. The path (text) is written correctly, the picture is in all lines the last one, the "Rollhocker".

              [0_1542625373820_2018-Sep.-20 14:37:30_Empfehlungen.odf](Uploading 100%)

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mvuori
                wrote on last edited by
                #11

                I looked at QTextCursor's cource code. The problem is the same name you give the images "Text" - because of that they all are the same resource, that is, the last one...

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #12

                  Sounds like a bug. Did you check the bug report system to see if there's something related ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    fmoerl
                    wrote on last edited by
                    #13

                    @mvuori : to my understanding, "Text" is optional, e.g. a subline, whereas the image is loaded above from different paths within sp3.

                    @SGaist : thanks, I reported a new bug: https://bugreports.qt.io/browse/QTBUG-71901?filter=-2

                    1 Reply Last reply
                    0
                    • F Offline
                      F Offline
                      fmoerl
                      wrote on last edited by fmoerl
                      #14

                      Until QTextCursor::InsertImage() is still buggy, I found a partial solution for filling the table with the right images. I replaced

                      cursor.insertImage(bild.scaledToWidth(200, Qt::SmoothTransformation), "Text");
                      

                      by

                      QString htmlimage; // some text to provide html-code
                      htmlimage.clear();
                      htmlimage.append("<img src=");
                      htmlimage.append(sp3.at(zdx)); // sp3 including the path to the specific image
                      htmlimage.append(" width=\"200\" height=\"150\">"); // no scaling, just setting to fix height and width
                      // now insert an image via html-code
                      cursor.insertFragment(QTextDocumentFragment::fromHtml(htmlimage));
                      

                      note1: there seems to be no scaling via html, thus, the images may be distorted.

                      note2: html-code don't like gaps. Beware of blanks within the path to the images.

                      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