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. Laying out text for letter to be displayed and printed
Qt 6.11 is out! See what's new in the release blog

Laying out text for letter to be displayed and printed

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.6k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I am trying to port a project of mine from java to cpp/qt

    Part of this involves displaying a page of text which includes a customer invoice with text in different fonts. In java I used a graphics2g pageformat and it was fairly straightforward working out the positions for text and laying out the text line by line. The page could then be sent to the screen or the printer.

    As a tyro in QT I do not know how to approach this and the documentation and examples are a little daunting. Should I be using a QGraphicsView to layout the text or a document or scribe class. I am having difficulty finding exactly where to start and what documentation will take me through this.

    Alan

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      The easiest would be to use a QPainter to do the drawing. It can draw to either a QPixmap to display on the screen or QPrinter for printing.

      Something along the lines of:
      @
      void MyClass::drawStuff(QPaintDevice& device) {
      QPainter p(&device);
      //use p to draw stuff
      }

      void MyClass::drawToScreen() {
      QPixmap pixmap(width, height);
      drawStuff(pixmap);
      //use the pixmap to display, e.g.
      someLabel->setPixmap(pixmap);
      }

      void MyClass::drawToPrinter {
      QPrinter printer;
      QPrintDialog dlg(&printer);
      if(dlg.exec() == QDialog::Accepted)
      drawStuff(printer);
      }
      @

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

        Hi and welcome to devnet,

        The code accompanying chapter 10 of "Advanced Qt Programming":http://www.qtrac.eu/aqpbook.html explains the various possibility you have quiet nicely.

        You also have several report generation libraries that you can use.

        Hope it helps

        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
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          Thanks. I'll give them both a try.

          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