Printer - One Record per page.
-
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 pageThanks in advance
-
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();
@ -
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()@