Search code examples
qtpdfqt4qtextdocument

Table and Image in a single page of QTextDocument in Qt4


I want to display a table and a image side by side. i.e Left side the image and right side the table. I want this because the image is the reference image for the data present in the table. I want that output in pdf. So I am using QTextDocument, QTextCursor and QPrinter to get the output in pdf. So how it is possible to display the image and table in QtextDocument i.e within a single page of the pdf? I am using Qt 4.5.3 and Windows Xp. Any pointers regarding this are welcome.


Solution

  • Hi i managed to do that. Just adding the snippet if someone might need that..

    QTextImageFormat m_ReferenceImageFormat; 
    m_ReferenceImageFormat.setWidth(525);
    m_ReferenceImageFormat.setHeight(450);
    m_ReferenceImageFormat.setName(imageFileName);
    m_pReportCursor->insertImage(m_ReferenceImageFormat,QTextFrameFormat::FloatRight);
    
    QTextTableFormat m_TableFormat;
    m_TableFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
        m_TableFormat.setAlignment(Qt::AlignTop);
        m_TableFormat.setWidth(400);
    m_pReportCursor->insertTable(5,2,m_TableFormat);
    // Table implementation goes here..
    

    Just make sure that the image and table are not overlapping. Adjust width and height accordingly. It should work fine. Thats all.