@mrjj I actually want to print to an actual printer. So, using a PDF in between is not an option.
Just as I said: the margins of the QPrinter::pageLayout() do not work as one would expect. In order to be able to print close to the border, you have to turn on full page mode and set the margins of the QPrinter directly. I am not entirely sure (as I have a huge code base involved converting wxWidgets to Qt), but it looks like setting the margins of QPrinter actually prints with that margin (in contrast to what the documentation suggests). For me the problems are now solved.
Hi Narayanan, Did you find any other alternative for this printer support on Android? Implementing ourselves is definitely an option but it can be quite a process if your application has to support more than 10 types of printers.
Do let me know as it would be helpful piece of information.
Let me tone down this discussion by saying that the original reason for my question has disappeared. I misunderstood how QPrinter worked. I thought I would need the string versions of the QPrintDialog enums to pass on to lp. Turns out QPrinter does what I need to do automatically and I don't need to call lp. Thanks for the lively discussion though.
it seems you made print in MainWindow::print
it should be in
TestPrint::print( QPrinter* printer )
That is why is says "print not declared in this scope" as
u seem to have pasted the code below it ?
That is ok. just correct code ( get rid of print call)
so first error is that you have no print function.
next error is that you miss the last argument for the text.
so yes, you are close to printing :)
if ( dialog.exec() == QDialog::Accepted )
// create painter for drawing print page
QPainter painter( &printer );
int w = printer.pageRect().width();
int h = printer.pageRect().height();
QRect page( 0, 0, w, h );
// create a font appropriate to page size
QFont font = painter.font();
font.setPixelSize( (w+h) / 100 );
painter.setFont( font );
// draw labels in corners of page
painter.drawText( page, Qt::AlignTop | Qt::AlignLeft, "QSimulate" );
painter.drawText( page, Qt::AlignBottom | Qt::AlignLeft, QString(getenv("USER")) );
//painter.drawText( page, Qt::AlignBottom | Qt::AlignRight,
// QDateTime::currentDateTime().toString( Qt::DefaultLocaleShortDate ) );
// draw simulated landscape
page.adjust( w/20, h/20, -w/20, -h/20 );
painter.drawText( &painter, page ); //testprint.cpp:78: error: no matching function for call to 'QPainter::drawText(QPainter*, QRect&)'
// here you have no text??
// look at the others, you need the last argument