Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTextDocument large distance between images
Qt 6.12 LTS is out! See what's new in the release blog

QTextDocument large distance between images

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 310 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.
  • M Offline
    M Offline
    Mihaill
    wrote on last edited by Mihaill
    #1

    Hi!
    I use qt 5.15
    I adding images in QTextDocument and in QTextDocument to be large distance between images. More empty space is added before and after the narrow image.

        QTextDocument textDocumentForPdf;
        
            QTextCursor cursor(&textDocumentForPdf);
        
            int widthPdf = widthImages * 0.9;
        
            int heightPdf = widthPdf * 1.41;
        
            for (int i = 0; i < m_arrDataForWriteReport.count(); i++) {
        
                cursor.insertImage(m_arrDataForWriteReport[i].m_image);
        
                cursor.insertImage(tableImages[i].scaled(widthImages, tableImages[i].height() *
        
                                                         double((double)widthImages / tableImages[i].width()),
        
                                                         Qt::KeepAspectRatio));
        
            }
        
            QPdfWriter writer(urlPath.toLocalFile() + ".pdf");
        
            writer.setPageSize(QPageSize(QSize(widthPdf, heightPdf)));
        
            textDocumentForPdf.print(&writer);
    

    1.png

    M 1 Reply Last reply
    0
    • M Mihaill

      Hi!
      I use qt 5.15
      I adding images in QTextDocument and in QTextDocument to be large distance between images. More empty space is added before and after the narrow image.

          QTextDocument textDocumentForPdf;
          
              QTextCursor cursor(&textDocumentForPdf);
          
              int widthPdf = widthImages * 0.9;
          
              int heightPdf = widthPdf * 1.41;
          
              for (int i = 0; i < m_arrDataForWriteReport.count(); i++) {
          
                  cursor.insertImage(m_arrDataForWriteReport[i].m_image);
          
                  cursor.insertImage(tableImages[i].scaled(widthImages, tableImages[i].height() *
          
                                                           double((double)widthImages / tableImages[i].width()),
          
                                                           Qt::KeepAspectRatio));
          
              }
          
              QPdfWriter writer(urlPath.toLocalFile() + ".pdf");
          
              writer.setPageSize(QPageSize(QSize(widthPdf, heightPdf)));
          
              textDocumentForPdf.print(&writer);
      

      1.png

      M Offline
      M Offline
      Mihaill
      wrote on last edited by
      #2

      @Mihaill If I merge 2 pictures into one, and add one picture, then it works fine

      1 Reply Last reply
      0
      • M Mihaill has marked this topic as solved on

      • Login

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