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. Formal letter with QTextDocument
Forum Updated to NodeBB v4.3 + New Features

Formal letter with QTextDocument

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 585 Views 2 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.
  • HoMaH Offline
    HoMaH Offline
    HoMa
    wrote on last edited by
    #1

    Hi everybody,

    this time I would like a more general question, conceptual, if you like.

    How would you implement a formal letter with header and fooder lines above /below everything on every page, logo on the first page top right, address field at the right positon etc.

    The goal would be to have pdf or odt files generated like a serial letter.
    The issue I see is, that it is hard, if not impossible, to position stuff on a page like with coordinates.
    I implemented the letter as a big table, but the code is long and does not look nice. It is also hard to maintain and not very flexible.
    Do you have other proposals?
    Regards
    Holger

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      One option is to use a report generator like
      https://sourceforge.net/projects/qtrpt/

      Other option is to use a SVG for the "fixed" stuff and
      paint the letter using QPainter.

      1 Reply Last reply
      0
      • HoMaH Offline
        HoMaH Offline
        HoMa
        wrote on last edited by
        #3

        @mrjj said in Formal letter with QTextDocument:

        SVG fo

        Thank you for your reply. I will have a look at the report generator. My first guess would be that serial letters are a kind of miss use - but however ;) if it works it would be fine.

        What exactly do you mean with "svg for the fixed stuff" ?
        Regards
        Holger

        mrjjM 1 Reply Last reply
        0
        • HoMaH HoMa

          @mrjj said in Formal letter with QTextDocument:

          SVG fo

          Thank you for your reply. I will have a look at the report generator. My first guess would be that serial letters are a kind of miss use - but however ;) if it works it would be fine.

          What exactly do you mean with "svg for the fixed stuff" ?
          Regards
          Holger

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @HoMa
          Hi
          Well a serial letter is not a report as such but its still just a layout which the report generator makes it easy to define.

          If you use inscape to make a template of the letter's layout and save as an SVG file you can use this file to paint first to a page using QPainter.
          SVG is vector and will scale to page size with no reduced quality,
          You then first paint the svg to a page with QPainter and then
          paint the text on top of this. Possible using a QTextDocument if you need rich text.
          If you tag elements in InkScape with an ID you know, you can get its area with
          https://doc.qt.io/qt-5/qsvgrenderer.html#boundsOnElement
          That makes it possible to have text place holders in the SVG file that you can use to know where to paint
          the text. But if its a very simply layout, this might be overkill :)

          1 Reply Last reply
          0
          • HoMaH Offline
            HoMaH Offline
            HoMa
            wrote on last edited by
            #5

            Thanks again!

            I got your point about SVG now! That would be good for the logo - right. And maybe the page header and footer. It would probably not work for the address field, which also has to have the fixed position about 6cm from the top, next to the left border or so.
            Anyhow: Seems I need to get more familiar with the QPainter ...

            Meanwhile I found QPrinterEasy by Eric Meaker. My first impression is that he combines QTextDocument and QPrinter to format a document with header, footer and watermark. When I am deeper in his code I think I should be able to get my serial letter done.

            Best regards
            Holger

            mrjjM 1 Reply Last reply
            0
            • HoMaH HoMa

              Thanks again!

              I got your point about SVG now! That would be good for the logo - right. And maybe the page header and footer. It would probably not work for the address field, which also has to have the fixed position about 6cm from the top, next to the left border or so.
              Anyhow: Seems I need to get more familiar with the QPainter ...

              Meanwhile I found QPrinterEasy by Eric Meaker. My first impression is that he combines QTextDocument and QPrinter to format a document with header, footer and watermark. When I am deeper in his code I think I should be able to get my serial letter done.

              Best regards
              Holger

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @HoMa
              Hi
              Well the SVG way is most useful if you got a very detailed page and you don't have to adjust positions
              according to content size.
              Anyhow, the QPrinterEasy sounds exactly what you want so I hope it will just compile in newer Qt versions.
              Good luck.

              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