本文整理汇总了C++中QPrintDialog::printer方法的典型用法代码示例。如果您正苦于以下问题:C++ QPrintDialog::printer方法的具体用法?C++ QPrintDialog::printer怎么用?C++ QPrintDialog::printer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPrintDialog
的用法示例。
在下文中一共展示了QPrintDialog::printer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: imprimir
/*!
* \fn FormSimularCuotas::imprimir()
* Imprime el listado de cuotas tal cual se ingresaron en los datos.
*/
void FormSimularCuotas::imprimir()
{
this->generaReporte();
QPrinter *impresora = new QPrinter( QPrinterInfo::defaultPrinter() );
QPrintDialog *pd = new QPrintDialog( impresora );
if( pd->exec() == QDialog::Accepted ) {
documento->print( pd->printer() );
}
delete impresora;
delete pd;
}
示例2: printFile
void MainWindow::printFile()
{
GRPrintPagesDlg pagesdlg;
if ( pagesdlg.exec() != QDialog::Accepted )
return;
int rows = pagesdlg.rows();
int columns = pagesdlg.columns();
QPrintDialog pr;
if ( pr.exec() == QDialog::Accepted )
{
QPrinter *qp = pr.printer();
int pwidth = qp->pageRect().width();
int pheight = qp->pageRect().height();
int npages = rows * columns;
int gwidth = columns * pwidth, gheight = rows * pheight;
QImage img(gwidth, gheight, QImage::Format_RGB444);
if ( img.isNull() )
return;
// render graph
QPainter gpaint;
gpaint.begin(&img);
gpaint.fillRect(img.rect(), Qt::white);
QFont f("courier", 12);
gpaint.setFont(f);
QRect text_rect = gpaint.fontMetrics().boundingRect(G_title);
int x = (gwidth - text_rect.width()) / 2;
gpaint.drawText(x, text_rect.height(), G_title);
PaintStruct ps;
ps.p = &gpaint;
ps.border = 60;
set_drawing_rectangle(gwidth-120, gheight-120);
display_complete_graph();
draw_graph(draw_line, draw_rect, draw_poly, &ps);
gpaint.end();
// copy to pages
QPainter prpaint;
prpaint.begin(qp);
QRect src;
QRect dst(0, 0, pwidth, pheight);
for ( int page = 0, col = 0, row = 0; page < npages; ++page )
{
src.setLeft(col*pwidth);
src.setTop(row*pheight);
src.setWidth(pwidth);
src.setHeight(pheight);
prpaint.drawImage(QPoint(0, 0), img, src);
// next
if ( page < npages - 1 )
qp->newPage();
if ( col < columns - 1 )
++col;
else
{
++row;
col = 0;
}
}
prpaint.end();
//this will reset the drawing rectangle to the canvas values
canvas->viewport()->repaint();
display_complete_graph();
}
}
示例3: print
bool ChequePrinter::print()
{
// 0. Amount to readable string
QString amount;
QStringList vals = Utils::doubleToHumanReadableString(d->_amount);
if (vals.count() == 0) {
LOG_ERROR_FOR("ChecquePrinter", "Wrong amount to string values");
} else {
amount = vals.at(0) + " " + QLocale().currencySymbol(QLocale::CurrencyDisplayName) + "s";
if (vals.count() == 2)
amount += QString(" %1 %2").arg(tkTr(Trans::Constants::AND)).arg(vals.at(1));
}
// Method 1. use pdkcompleter
// Internal::PdfTkWrapper *pdftk = Internal::PdfTkWrapper::instance();
// if (!pdftk->initialize())
// return false;
// pdftk->beginFdfEncoding();
// pdftk->addFdfValue("date", QLocale().toString(d->_date, QLocale::ShortFormat));
// pdftk->addFdfValue("lieu", d->_place);
// pdftk->addFdfValue("ordre", d->_order);
// pdftk->addFdfValue("montant1", lines.at(0));
// if (lines.count() >= 2)
// pdftk->addFdfValue("montant2", lines.at(1));
// // Amount to translated number
// QSystemLocale::CurrencyToStringArgument arg;
// arg.value = d->_amount;
// QVariant var;
// var.setValue<QSystemLocale::CurrencyToStringArgument>(arg);
// pdftk->addFdfValue("num", QString::number(d->_amount, 'f', 2)); //QSystemLocale().query(QSystemLocale::CurrencyToString, var).toString());
// QString filename = "/Users/eric/Desktop/cheque.pdf";
// pdftk->endFdfEncoding(filename);
// pdftk->fillPdfWithFdf(filename, pdftk->getFdfContent(), "/Users/eric/Desktop/test_cheque.pdf", "ISO-8859-1");
// return true;
// Method 2. use QPainter/QPrinter
// try to use the default printer
QPrintDialog dlg;
if (dlg.exec()==QDialog::Rejected)
return false;
QPrinter *printer = dlg.printer();
// printer->setPaperSource(QPrinter::PaperSource);
printer->setFullPage(true);
printer->setPaperSize(QPrinter::A4);
printer->setResolution(150);
printer->setOrientation(QPrinter::Landscape);
d->_axisHelper.setPageSize(printer->paperRect(), printer->paperSize(QPrinter::Millimeter));
QPainter painter;
if (!painter.begin(printer)) { // failed to open file
qWarning("failed to open file, is it writable?");
return false;
}
painter.save();
QFont font;
font.setPointSize(10);
painter.setFont(font);
painter.translate(d->_axisHelper.pointToPixels(120, 61));
// 25,17 pour certains
// 45,13 pour d'autres
QRectF amountLines(d->_axisHelper.pointToPixels(45,13), d->_axisHelper.sizeToPixels(90, 10));
// QRect amountLine2(d->_axisHelper.pointToPixels(10,23), d->size(110, 5));
QRectF orderLine(d->_axisHelper.pointToPixels(10,28), d->_axisHelper.sizeToPixels(110, 5));
QRectF numberLine(d->_axisHelper.pointToPixels(133,28), d->_axisHelper.sizeToPixels(41, 10));
QRectF placeLine(d->_axisHelper.pointToPixels(133,38), d->_axisHelper.sizeToPixels(40, 4));
QRectF dateLine(d->_axisHelper.pointToPixels(133,42), d->_axisHelper.sizeToPixels(40, 4));
if (DrawChequeRects) {
painter.drawRect(amountLines);
painter.drawRect(orderLine);
painter.drawRect(numberLine);
painter.drawRect(placeLine);
painter.drawRect(dateLine);
}
if (amount.count() > 50)
amount = Utils::lineWrapString(amount, 50);
amount = QString("****%1****").arg(amount.toUpper());
QFontMetrics metrics(font);
while (metrics.width(amount) > amountLines.width() || font.pointSize() == 6) {
font.setPointSizeF(font.pointSizeF() - .1);
metrics = QFontMetrics(font);
}
painter.setFont(font);
painter.drawText(amountLines, Qt::AlignLeft, amount);
font.setPointSize(10);
painter.setFont(font);
// QStringList lines = amount.split("\n", QString::SkipEmptyParts);
// painter.drawText(amountLine1, Qt::AlignLeft | Qt::AlignVCenter, lines.at(0));
// if (lines.count() >= 2)
// painter.drawText(amountLine2, Qt::AlignLeft | Qt::AlignVCenter, lines.at(1));
//.........这里部分代码省略.........