Solved QPrinter margins
-
Hi
Most printers have a non printable margin where its not possible to print.
Often around 6.35 mm -
Hi, thank you for your response...
But when I use Painter to print it´s posssible with margin=0.
I made 3 tests:
1)using painter.drawtext(0,0,0,0, text) and the text was printed at the top of the paper with margin 02)using :
QTextEdit teste3;
teste3.setPlainText(text);
teste3.print(&printer);
This print the same text, but with a paper margin.3)using
QTextDocument *document = new QTextDocument();
printer.setFullPage(true);
document->setPlainText(text);
document->print(&printer);
The results are the same of test (2)I tried to set printer.setPageMargins(0,0,0,0,QPrinter::Millimeter)...nothing
when I use printer.setPageMargins(10,10,10,10,QPrinter::Millimeter)...the margin increase.
My app will print to a ribbon printer (I don´t know if it´s a correct name ...I´m from Brazil )...this will used for print restaurant order food in a small ribbon printer ).
-
@Guapo
Oh
Its a ribbon printer. ( Google agree its the correct name :)If you can print at 0,0 and text is shown then it must be able to print
to the very border. Maybe it reports some margin from the OS/driverCan you try something like
printer.setFullPage(true); // must be before setmargin
printer.setPageMargins(QMarginsF(0,0,0,0));
qDebug() << "new margins:" << printer->pageLayout().margins();I think it might relate to
https://bugreports.qt.io/browse/QTBUG-32987 -
@mrjj said in QPrinter margins:
If you can print at 0,0 and text is shown then it must be able to print
to the very border. Maybe it reports some margin from the OS/driveHi @mrjj,
let me explain better....I will use a ribbon printer, but now I´m using EPSON L355 bulk ink.this is the result after new setup: >> new margins: QMarginsF(0, 0, 0, 0)
it looks like the change the printer config but the results are the same.I include 2 files with the result from printer and painter:
printer: ( up and left margins )
using painter: this print doesn´t have any margins (up and left)...I used this paper to make several tests....:)
-
Must mean that QTextDocument looks up its own margins.
I could not find any further info on this.You could look in the source code to see what is going on.
If anything else fails, you can define a new custom page for the printer that has no
margins. -
@mrjj, I think you all right. You help me to understand I´m going to the right way.
Thanks for your help.
-
I think after you set printers margin to zero you need something like
document.setPageSize(QSizeF(printer.pageRect().size()));
So doc get its page size updated.as in
printer.setFullPage(true); // must be before setmargin
printer.setPageMargins(QMarginsF(0,0,0,0));
document.setPageSize(QSizeF(printer.pageRect().size()));
..print.. -
@mrjj, almost there....this hint cuts the first line and first column. But print at 0,0.
I´m sure this is the way.
-
@Guapo said in QPrinter margins:
@mrjj, almost there....this hint cuts the first line and first column. But print at 0,0.
I´m sure this is the way.
I don´t know what´s happen before with the firs line....this is not true...only cuts the first column. I´m trying to understand.
-
In another thread I saw QtextDocument unit is point (pt) and
const qreal PT_MM = 25.4/72.0;
document->setPageSize(QSizeF(printer.pageRect().size()));
document->setDocumentMargin(5.0/PT_MM); // sets margin to 5mmthe complete function is here:
QString text ="\n" "1PRINT BY PRINTER sectetur adipisicing elit, sed do\n" "2eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut\n" "3eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut\n" "4nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor\n" "5in reprehenderit in voluptate velit esse cillum dolore eu fugiat\n" "6nulla pariatur. Excepteur sint occaecat cupidatat non proident,\n" "7sunt in culpa qui officia deserunt mollit anim id est laborum.\n" "8Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do\n" "9eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut\n" "20sunt in culpa qui officia deserunt mollit anim testao.\n"; QPrinter printer; printer.setFullPage(true); // must be before setmargin qDebug() << "new margins:" << printer.pageLayout().margins(); printer.setPageMargins(QMarginsF(0,0,0,0)); qDebug() << "new margins:" << printer.pageLayout().margins() << printer.pageRect().size(); QPrintDialog *dialog = new QPrintDialog(&printer); dialog->setWindowTitle("Imprimir Nota"); if (dialog->exec() == QDialog::Rejected) return; const qreal PT_MM = 25.4/72.0; QTextDocument *document = new QTextDocument(); document->setPageSize(QSizeF(printer.pageRect().size())); document->setDocumentMargin(5.0/PT_MM); document->setPlainText(text); document->print(&printer);
it´s working!!!!
@mrjj, thank you very much for your help!!!
-
Ahh super
it was in points, missed that.