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. Questions and Problems Regarding QPrint
QtWS25 Last Chance

Questions and Problems Regarding QPrint

Scheduled Pinned Locked Moved General and Desktop
qprint
4 Posts 3 Posters 1.5k 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.
  • C Offline
    C Offline
    Corpse0327
    wrote on last edited by Corpse0327
    #1

    Hello all

    I have a few questions regarding QPrint

    1. If some part of the text is bold how can i do it so it will be bold. I tried wrapping the text between <B></B> and [B][/B]

    2. I want to keep things tidy like a grid and put texts inside those. How can i achieve a neat structure. I tried adding spaces manually. However not every character have the same width, especially space, and keeping them tidy is hard. Example:

      Name : Value <enough space here> Name2 : Value2
      Name1 : Value1 <enough space here> Name3 : Value3
      ...

    3. When i use the code below. Although left and top margins are not passed over, right margin is passed over. I just can't understand why. I don't want to use '\n' manually.

      QPrinter printer(QPrinter::HighResolution);
      printer.setPageSize(QPrinter::A4);
      printer.setOrientation(QPrinter::Portrait);
      printer.setPageMargins (15, 15, 15, 15, QPrinter::Point);
      printer.setFullPage(false);
      printer.setOutputFileName("çıktı.pdf");
      printer.setOutputFormat(QPrinter::PdfFormat);
      QPainter painter(&printer);
      painter.setFont(QFont("Tahoma", 8));

      painter.drawText(printer.pageRect(), result);

    Thanks in advance.

    mrjjM A 2 Replies Last reply
    0
    • C Corpse0327

      Hello all

      I have a few questions regarding QPrint

      1. If some part of the text is bold how can i do it so it will be bold. I tried wrapping the text between <B></B> and [B][/B]

      2. I want to keep things tidy like a grid and put texts inside those. How can i achieve a neat structure. I tried adding spaces manually. However not every character have the same width, especially space, and keeping them tidy is hard. Example:

        Name : Value <enough space here> Name2 : Value2
        Name1 : Value1 <enough space here> Name3 : Value3
        ...

      3. When i use the code below. Although left and top margins are not passed over, right margin is passed over. I just can't understand why. I don't want to use '\n' manually.

        QPrinter printer(QPrinter::HighResolution);
        printer.setPageSize(QPrinter::A4);
        printer.setOrientation(QPrinter::Portrait);
        printer.setPageMargins (15, 15, 15, 15, QPrinter::Point);
        printer.setFullPage(false);
        printer.setOutputFileName("çıktı.pdf");
        printer.setOutputFormat(QPrinter::PdfFormat);
        QPainter painter(&printer);
        painter.setFont(QFont("Tahoma", 8));

        painter.drawText(printer.pageRect(), result);

      Thanks in advance.

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

      @Corpse0327
      Hi
      you would set the font bold.

      1:
       QFont f("Tahoma", 18);
        f.setBold(true);
        painter.setFont(f);
      

      2:

      Well you could use tabs or position the text yourself. like
      QString t1("Peter:400");
      QString t2("Thomas:400");
      int aw=painter.fontMetrics().averageCharWidth();
      painter.drawText(60, 100, t1);
      painter.drawText(60+(aw*20), 100, t2); // next col 20 chars out
      

      Basically you "print" as would would draw something on screen.
      Some of the controls, like TextDocument can print them self also.

      1 Reply Last reply
      0
      • C Corpse0327

        Hello all

        I have a few questions regarding QPrint

        1. If some part of the text is bold how can i do it so it will be bold. I tried wrapping the text between <B></B> and [B][/B]

        2. I want to keep things tidy like a grid and put texts inside those. How can i achieve a neat structure. I tried adding spaces manually. However not every character have the same width, especially space, and keeping them tidy is hard. Example:

          Name : Value <enough space here> Name2 : Value2
          Name1 : Value1 <enough space here> Name3 : Value3
          ...

        3. When i use the code below. Although left and top margins are not passed over, right margin is passed over. I just can't understand why. I don't want to use '\n' manually.

          QPrinter printer(QPrinter::HighResolution);
          printer.setPageSize(QPrinter::A4);
          printer.setOrientation(QPrinter::Portrait);
          printer.setPageMargins (15, 15, 15, 15, QPrinter::Point);
          printer.setFullPage(false);
          printer.setOutputFileName("çıktı.pdf");
          printer.setOutputFormat(QPrinter::PdfFormat);
          QPainter painter(&printer);
          painter.setFont(QFont("Tahoma", 8));

          painter.drawText(printer.pageRect(), result);

        Thanks in advance.

        A Offline
        A Offline
        aliks-os
        wrote on last edited by
        #3

        @Corpse0327

        QPrinter printer(QPrinter::HighResolution);
        printer.setPageSize(QPrinter::A4);
        printer.setOrientation(QPrinter::Portrait);
        printer.setPageMargins (15, 15, 15, 15, QPrinter::Point);
        printer.setFullPage(false);
        printer.setOutputFileName("çıktı.pdf");
        printer.setOutputFormat(QPrinter::PdfFormat);
        QPainter painter(&printer);
        QFont font = painter.font();
        font.setBold(true);
        painter.setFont(font);
        painter.drawText(printer.pageRect(), result);
        
        mrjjM 1 Reply Last reply
        0
        • A aliks-os

          @Corpse0327

          QPrinter printer(QPrinter::HighResolution);
          printer.setPageSize(QPrinter::A4);
          printer.setOrientation(QPrinter::Portrait);
          printer.setPageMargins (15, 15, 15, 15, QPrinter::Point);
          printer.setFullPage(false);
          printer.setOutputFileName("çıktı.pdf");
          printer.setOutputFormat(QPrinter::PdfFormat);
          QPainter painter(&printer);
          QFont font = painter.font();
          font.setBold(true);
          painter.setFont(font);
          painter.drawText(printer.pageRect(), result);
          
          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @aliks-os
          Should work yes.

          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