Results 1 to 17 of 17

Thread: Creating documents from Qt

  1. #1
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Creating documents from Qt

    Hi all
    I am working on a project where we need to produce documents (in a platform independent way) from data held withing the application.
    Does anyone have any recomendations on how this can be achieved?

    TIA

    Graham

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Creating documents from Qt

    What kind of documents? TXT files are platform independent No seriously, why not using pdf for that?

    EDIT: For pdf use a QPainter on a QPrinter and save that as pdf.

  3. #3
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Creating documents from Qt

    Hi - thanks for replying
    Forgive my ignorance, I am completely new to QT.
    I am currently redesigning/rewriting an exiting MS application to use QT so we can take advantage of platform and language independence that QT offers.
    Currently the application produces a simplistic plain text document, but our customers want a professional looking document- currently they use our data to produce a MS Word document.

    How easy is it to produce a PDF document? (how does one do it)?
    Is there an advantage to using something like ODF? (would our customers be able to read the document)

    TIA
    Graham

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Creating documents from Qt

    Well it depends what your customer want to do with the document. If don't want to change it, I would go for pdf, since then it is guaranteed, that it look everywhere the same and you can store the document a long time. If you want to change values then of course go for odf. But it sounds like your costumer only wants something to print out.

    For pdf there are some examples, but effectively it is nothing else than painting (using QPainter) on a defined piece of paper where you have to positioning the elements. One nice thing is that you can also use a QTextDocument for more advanced text documents and print it directly using QTextDocument::print().

  5. The following user says thank you to Lykurg for this useful post:

    GrahamLabdon (23rd April 2010)

  6. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Creating documents from Qt

    I don't know if you have found that: http://doc.trolltech.com/qq/qq27-odfwriter.html. It's an good article for starting. Even if it is for odt.

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Creating documents from Qt

    A good idea is to render the document into html and then print it to pdf from WebKit using means already mentioned by Lykurg.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #7
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Creating documents from Qt

    Thanks everyone

  9. #8
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Creating documents from Qt

    Hi everyone
    I used the code from the QT Quarterly suggested by Lykurg to produce a odt document.
    However when I try to open with MS Word it refuses as it says that the file couild not be opened - 'the open office XML .. file could not be opened' the details tab gives 'the file is corrupt and could not be opened'

    Any ideas?

    Graham

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Creating documents from Qt

    MS Word can't open ODT files without a dedicated filter.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #10
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Creating documents from Qt

    Hi wysota

    What filter do I need?

  12. #11
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Creating documents from Qt

    Ask google for "word odf"... E.g. http://sourceforge.net/projects/odf-converter/

  13. #12
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Creating documents from Qt

    Thanks Lykurg
    I have downloaded the odf-converter and can now open the generated odt file, however, the formating is all lost and does not look like the example given
    any more ideas?
    Graham

  14. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Creating documents from Qt

    Do you require the document to be editable in Word or is it just something you would like to have?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #14
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Creating documents from Qt

    The document should be editable in word and preferably on MAC and *nix

  16. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Creating documents from Qt

    *should* or *has to*? If it has to be editable on all of those platforms then your only choice is RTF. Just know there is no direct support for it in Qt.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #16
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Creating documents from Qt

    Hi
    I am still playing with odt documents.
    I have created a document within a QT application and am using OpenXML/ODF Translator Add-in for Office to convert it.
    The document contains a table and an image.
    When I open the document I see the plain text and the table, but the format I applied to the table is not visible (solid borders) and I see no image. Do you have any ide why this is?

    Code for table
    Qt Code:
    1. m_cursor.insertText(QObject::tr(
    2. "Phone bill for %1\n").arg(client));
    3.  
    4. QTextTableFormat tableFormat;
    5. tableFormat.setBorderStyle(
    6. QTextFrameFormat::BorderStyle_Double);
    7. m_cursor.insertTable(1, 3,tableFormat);
    8. m_cursor.insertText(QObject::tr("Date"));
    9. m_cursor.movePosition(QTextCursor::NextCell);
    10. m_cursor.insertText(QObject::tr("Duration (sec)"));
    11. m_cursor.movePosition(QTextCursor::NextCell);
    12. m_cursor.insertText(QObject::tr("Cost"));
    To copy to clipboard, switch view to plain text mode 

    Code for image
    Qt Code:
    1. const int columnSize = 10;
    2. int width = values.count() * columnSize;
    3. int max = 0;
    4. foreach (int x, values)
    5. max = qMax(max, x);
    6. QImage image(width, 100, QImage::Format_Mono);
    7. QPainter painter(&image);
    8. painter.fillRect(0, 0, image.width(), image.height(),
    9. Qt::red); // background
    10. for (int index = 0; index < values.count(); ++index) {
    11. // Adjust scale to our 100 pixel tall image:
    12. int height = values[index] * 100 / max;
    13. painter.fillRect(index * columnSize,
    14. image.height() - height, columnSize, height,
    15. Qt::black);
    16. }
    17. painter.end();
    18.  
    19. QTextCursor cursor(m_document);
    20. cursor.movePosition(QTextCursor::End);
    21. cursor.insertText(subtext);
    22. cursor.insertBlock();
    23.  
    24.  
    25. cursor.insertImage(image);
    To copy to clipboard, switch view to plain text mode 

    TIA

    Graham

  18. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Creating documents from Qt

    In my opinion you are just wasting your time. You will never be able to preserve complete formatting this way. You will lose some first when you export the document from Qt (as the odt writer is not 100% compliant with OpenOffice's odf reader) and then you'll lose some again trying to convert to Word. If you are after displaying the document then use PDF. If you are after editing it, use RTF. If you are after editing it and don't mind buying additional software, use PDF and use Acrobat (or equivalent) to edit the document.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  19. The following user says thank you to wysota for this useful post:

    GrahamLabdon (26th April 2010)

Similar Threads

  1. QDockWidget and Multiple Documents
    By freelucas in forum Qt Programming
    Replies: 0
    Last Post: 19th February 2010, 11:44
  2. Can Qt handle pdf documents???
    By webquinty in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 23rd March 2009, 15:16
  3. QDirModel displaying Desktop and Documents
    By JimDaniel in forum Qt Programming
    Replies: 2
    Last Post: 8th February 2008, 04:45
  4. Help creating a PDF doc
    By Dark_Tower in forum Qt Programming
    Replies: 5
    Last Post: 10th December 2006, 12:43
  5. opengl documents
    By neomax in forum General Discussion
    Replies: 1
    Last Post: 20th November 2006, 07:27

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.