Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Printer - One Record per page.

Printer - One Record per page.

Scheduled Pinned Locked Moved Language Bindings
8 Posts 2 Posters 4.5k 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.
  • A Offline
    A Offline
    AnnaBach
    wrote on last edited by
    #1

    Hi friends,

    Having a sqlite datafile (id,name,agreement) I wanted send to printer
    the sorted names of all records, with yes at agreement, but each name at center
    of 1 page, using only plain python and Qt. But Im lost to
    figure how print each sqlite name field 1 per page in Qt.

    Some gentle soul can post a simple snippet code of the process?
    Anna->Eject A4 page->Cindy->Eject A4 page->Mary->Eject A4 page

    Thanks in advance

    1 Reply Last reply
    0
    • L Offline
      L Offline
      loladiro
      wrote on last edited by
      #2

      What exactly do you have trouble with? Is it how to print in general or only printing one name a page?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AnnaBach
        wrote on last edited by
        #3

        Hi,

        The focus is: select 1 name and print it at center of a4 page -> do it with all names of sqlite database. blushes

        What im getting is many pages with all names of database filling the page area.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          loladiro
          wrote on last edited by
          #4

          Here you go (untested but it should work):
          @
          QPrinter printer;
          QPainter painter;
          QSqlQuery query("SELECT * FROM table");
          painter.begin(&printer);
          while (query.next()) {
          QString name = query.value(0).toString();
          QRect textSize = painter.front().boundingRect(name);
          printer.drawText(QRectF((printer.width()-textSize.width)/2,(printer.height()-textSize.height())/2,textSize.width(),textSize.height()),Qt::AlignCenter,name)
          printer.newPage();
          }
          painter.end();
          @

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AnnaBach
            wrote on last edited by
            #5

            Hum... i converted the snippet to python but running it nothing happens...
            (im away from printer now so choose to test it printing to pdf)

            @from PyQt4.QtCore import *
            from PyQt4.QtGui import *
            from PyQt4.QtSql import *

            db = QSqlDatabase.addDatabase("QSQLITE")
            db.setDatabaseName("data.db")

            printer = QPrinter(QPrinter.HighResolution)
            printer.setPageSize(QPrinter.A4)
            printer.setOutputFormat(QPrinter.PdfFormat)
            printer.setOutputFileName("test.pdf")

            painter = QPainter(printer)

            query = QSqlQuery("SELECT * FROM insc")

            start = painter.begin()

            while query.next():
            name = QString(query.value(0).toString())
            textSize = QRect(painter.front().boundingRect(name))
            printer.drawText = QRectF((printer.width()-textSize.width)/2,(printer.height()-textSize.height())/2,textSize.width(),textSize.height())
            printer.newPage()
            painter.end()@

            1 Reply Last reply
            0
            • L Offline
              L Offline
              loladiro
              wrote on last edited by
              #6

              shouldn't it be
              @printer.drawText(QRectF((printer.width()-textSize.width)/2,(printer.height()-textSize.height())/2,textSize.width(),textSize.height()))
              @ (I'm not that familiar with python, but it's still a method, right?

              1 Reply Last reply
              0
              • A Offline
                A Offline
                AnnaBach
                wrote on last edited by
                #7

                Oops. Worked. Thank you very much.

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  loladiro
                  wrote on last edited by
                  #8

                  Great! Could you please add [Solved] in front of the title? (Edit the first post)

                  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