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. How do you add Header/Footer in QTextDocument
Forum Updated to NodeBB v4.3 + New Features

How do you add Header/Footer in QTextDocument

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 1.8k Views 3 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.
  • D Offline
    D Offline
    deleted385
    wrote on last edited by
    #1

    Out of the box it gives me a table with page number at bottom:

    void QueryResultView::printTable()
    {
        int row = table->model()->rowCount();
        int column = table->model()->columnCount();
        QPrinter printer;
        printer.setPageSize(QPageSize::A4);
        printer.setOutputFormat(QPrinter::PdfFormat);
        printer.setOutputFileName("test.pdf");
        QTextDocument doc;
        QTextCursor cursor(&doc);
        QTextTableFormat tableFormat;
        tableFormat.setBorderCollapse(true);
        tableFormat.setHeaderRowCount(row);
        cursor.insertTable(row, column);
        for (int r = 0; r < row; r++) {
            for (int c = 0; c < column; c++) {
                auto index = table->model()->index(r, c);
                cursor.insertText( table->model()->data(index).toString() );
                cursor.movePosition(QTextCursor::NextCell);
            }
        }
        doc.print(&printer);
    }
    

    How to add page header/footer as well as table column header on each page?

    JonBJ 1 Reply Last reply
    0
    • HoMaH HoMa

      I found this example interesting: https://github.com/jeromecc/qprintereasy

      best regards
      HoM

      D Offline
      D Offline
      deleted385
      wrote on last edited by
      #8

      @HoMa, this, probably, is the simplest possible way.

      1 Reply Last reply
      0
      • D deleted385

        Out of the box it gives me a table with page number at bottom:

        void QueryResultView::printTable()
        {
            int row = table->model()->rowCount();
            int column = table->model()->columnCount();
            QPrinter printer;
            printer.setPageSize(QPageSize::A4);
            printer.setOutputFormat(QPrinter::PdfFormat);
            printer.setOutputFileName("test.pdf");
            QTextDocument doc;
            QTextCursor cursor(&doc);
            QTextTableFormat tableFormat;
            tableFormat.setBorderCollapse(true);
            tableFormat.setHeaderRowCount(row);
            cursor.insertTable(row, column);
            for (int r = 0; r < row; r++) {
                for (int c = 0; c < column; c++) {
                    auto index = table->model()->index(r, c);
                    cursor.insertText( table->model()->data(index).toString() );
                    cursor.movePosition(QTextCursor::NextCell);
                }
            }
            doc.print(&printer);
        }
        

        How to add page header/footer as well as table column header on each page?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #2

        @Emon-Haque
        You can't. Google Header Footer QTextDocument. Unless you're keen enough to want to do the low-level drawText/pageRect stuff to roll your own, e.g. https://forum.qt.io/topic/5152/adding-a-footer-to-a-qtextdocument/2

        D 1 Reply Last reply
        2
        • JonBJ JonB

          @Emon-Haque
          You can't. Google Header Footer QTextDocument. Unless you're keen enough to want to do the low-level drawText/pageRect stuff to roll your own, e.g. https://forum.qt.io/topic/5152/adding-a-footer-to-a-qtextdocument/2

          D Offline
          D Offline
          deleted385
          wrote on last edited by deleted385
          #3

          @JonB, it should have some simpler class to make tabular report. Everyone has those things.

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

            Hi,

            https://www.kdab.com/development-resources/qt-tools/kd-reports/
            https://ncreportsoftware.com/
            https://cute-report.com/
            http://limereport.sourceforge.net/

            And there are likely other Qt based tools to build reports.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

              I found this example interesting: https://github.com/jeromecc/qprintereasy

              best regards
              HoM

              D 2 Replies Last reply
              1
              • HoMaH HoMa

                I found this example interesting: https://github.com/jeromecc/qprintereasy

                best regards
                HoM

                D Offline
                D Offline
                deleted385
                wrote on last edited by
                #6

                @HoMa, will look at that soon. Thanks for sharing the link.

                1 Reply Last reply
                0
                • SGaistS SGaist

                  Hi,

                  https://www.kdab.com/development-resources/qt-tools/kd-reports/
                  https://ncreportsoftware.com/
                  https://cute-report.com/
                  http://limereport.sourceforge.net/

                  And there are likely other Qt based tools to build reports.

                  D Offline
                  D Offline
                  deleted385
                  wrote on last edited by
                  #7

                  @SGaist, those are heavy library and probably is suitable for business.

                  What about individuals and others who want to have something like WPF's Fixed/FlowDocuments to create their own lightweight reports?

                  1 Reply Last reply
                  0
                  • HoMaH HoMa

                    I found this example interesting: https://github.com/jeromecc/qprintereasy

                    best regards
                    HoM

                    D Offline
                    D Offline
                    deleted385
                    wrote on last edited by
                    #8

                    @HoMa, this, probably, is the simplest possible way.

                    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