PDA

View Full Version : QT and Dotmatrix printing



neveffects
16th February 2010, 12:29
Hi Everybody,
I have built an application in Qt 3.3.4 and will generate a Report and should be printed using a Dot Matrix Printer directly from the application. Now we are doing this by generating the report in an excel format and the and save this file as a .csv file and then using a driver this csv file is processed and send this to the dot matrix printer through an applet and printing. but this will be very difficult for an end user. Expecting Ideas.....


Here is Sample code for the text printing:

while clicking a print button the signal will execute the following code:

void RptPrintDlg::printPayslip(){
#ifndef QT_NO_PRINTER
QPrinter printer;
printer.setFullPage(TRUE);

if ( printer.setup( this ) ) {

QPainter p( &printer );
QPaintDeviceMetrics metrics(p.device());

int dpix = metrics.logicalDpiX();
int dpiy = metrics.logicalDpiY();
const int margin =20; // pt old Margin 72
QRect body(margin*dpix/72, margin*dpiy/72,
metrics.width()-margin*dpix/72*2,
metrics.height()-margin*dpiy/72*2);

QSimpleRichText richText( txeReport->text(), QFont(), txeReport->context(), txeReport->styleSheet(),
txeReport->mimeSourceFactory(), body.height());

richText.setWidth( &p, body.width());
QRect view( body );
int page = 1;
do {
richText.draw( &p, body.left(), body.top(), view, colorGroup() );
view.moveBy( 0, body.height() );
p.translate( 0 , -body.height() );
p.drawText( view.right() - p.fontMetrics().width( QString::number(page) ),
view.bottom() + p.fontMetrics().ascent() + 5, QString::number(page) );
if ( view.top() >= richText.height() )
break;
printer.newPage();
page++;
} while (TRUE);
}
#endif

}