premroxx
3rd December 2014, 22:48
I want to create a form that the user fills in and when he clicks save. it saves in the Pdf format(Letter size)
1) What are the dimension of the gui/form to fit the Letter format(81/2 by 11 inches)
2) What method do I use to print to pdf
The following is what I have so far. The issues I have with is that it prints completely out of proportion. I have a feeling there is better way to print it to pdf
QPixmap pixmap;
pixmap=QPixmap::grabWindow(ui->centralWidget->winId());
QPrinter printer;
printer.setOrientation(QPrinter::Portrait);
printer.setPageSize(QPrinter::A4);
printer.setOutputFormat(QPrinter::PdfFormat);
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),"untitled",tr("PDF Document (*.pdf)"));
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(fileName);
QPainter painter(&printer);
QRect rect=painter.viewport();
QSize size=pixmap.size();
size.scale(rect.size(), Qt::KeepAspectRatio);
painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
painter.setWindow(pixmap.rect());
painter.drawPixmap(0,0,pixmap);
1) What are the dimension of the gui/form to fit the Letter format(81/2 by 11 inches)
2) What method do I use to print to pdf
The following is what I have so far. The issues I have with is that it prints completely out of proportion. I have a feeling there is better way to print it to pdf
QPixmap pixmap;
pixmap=QPixmap::grabWindow(ui->centralWidget->winId());
QPrinter printer;
printer.setOrientation(QPrinter::Portrait);
printer.setPageSize(QPrinter::A4);
printer.setOutputFormat(QPrinter::PdfFormat);
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),"untitled",tr("PDF Document (*.pdf)"));
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(fileName);
QPainter painter(&printer);
QRect rect=painter.viewport();
QSize size=pixmap.size();
size.scale(rect.size(), Qt::KeepAspectRatio);
painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
painter.setWindow(pixmap.rect());
painter.drawPixmap(0,0,pixmap);