当前位置: 首页>>代码示例>>C++>>正文


C++ QPrinter::setPageMargins方法代码示例

本文整理汇总了C++中QPrinter::setPageMargins方法的典型用法代码示例。如果您正苦于以下问题:C++ QPrinter::setPageMargins方法的具体用法?C++ QPrinter::setPageMargins怎么用?C++ QPrinter::setPageMargins使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QPrinter的用法示例。


在下文中一共展示了QPrinter::setPageMargins方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: saveAsDocument

void PageScreen::saveAsDocument(const QString &format)
{
    const QString &suffix = QLatin1Char('.') + format.toLower();

    QString pathWithoutSuffix = ui->location->text();
    if (pathWithoutSuffix.endsWith(suffix, Qt::CaseInsensitive)) {
        pathWithoutSuffix = pathWithoutSuffix.mid(0, pathWithoutSuffix.length() - suffix.length());
    }

    QPrinter printer;
    printer.setCreator(QupZilla::tr("QupZilla %1 (%2)").arg(QupZilla::VERSION, QupZilla::WWWADDRESS));
    printer.setOutputFileName(pathWithoutSuffix + suffix);
    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setPaperSize(m_pageImages.first().size(), QPrinter::DevicePixel);
    printer.setPageMargins(0, 0, 0, 0, QPrinter::DevicePixel);
    printer.setFullPage(true);

    QPainter painter;
    painter.begin(&printer);

    for (int i = 0; i < m_pageImages.size(); ++i) {
        const QImage &image = m_pageImages.at(i);
        painter.drawImage(0, 0, image);

        if (i != m_pageImages.size() - 1) {
            printer.newPage();
        }
    }

    painter.end();
}
开发者ID:Alternate20,项目名称:qupzilla,代码行数:31,代码来源:pagescreen.cpp

示例2: printReport

//! Print the checked in and missing items.
void wndInventoryCheck::printReport( void )
{
    QPrinter printer;
    printer.setPaperSize( QPrinter::Letter );
    printer.setPageMargins( 1, 1, 1, 1, QPrinter::Inch );

    QPrintDialog *dialog = new QPrintDialog( &printer, this );
    if ( dialog->exec() != QDialog::Accepted )
    {
        return;
    }

    // PDF printing:
    //printer.setOutputFormat(QPrinter::PdfFormat);
    //printer.setOutputFileName("test.pdf");

    // Build the painter data which is printed
    QPainter painter;

    if ( !painter.begin( &printer ) ) // Link the painter to the printer
    {
        qWarning("Printer Error: Could not link painter to printer. ");
        return;
    }

    painter.setFont( QFont( "Courier New", 12, QFont::Bold ) );

    int pw = (int)( printer.pageRect( QPrinter::DevicePixel ).width() );
    int ph = (int)( printer.pageRect( QPrinter::DevicePixel ).height() );
    int y = 0;
    painter.drawText( 0, 0, pw, ph, Qt::AlignHCenter, "Station 40 - Youngsville Fire Department\n"
                     "Inventory Audit Report\n"  + QDate::currentDate().toString( "dddd the d of MMMM yyyy" ) );
    y = 80;
    if ( _pUI->chkCheckedItems->isChecked() )
    {
        painter.drawText( 0, y, pw, ph, Qt::AlignLeft, "Checked Items" );
        y += 20;

        for ( int i = 0; i < _pUI->tblCheckedIn->model()->rowCount(); i++ )
        {
            painter.drawText( 20, y, pw, ph, Qt::AlignLeft, _pUI->tblCheckedIn->model()->index( i, 1 ).data().toString() );
            y += 20;
        }
    }

    if ( _pUI->chkMissingItems->isChecked() )
    {
        painter.drawText( 0, y, pw, ph, Qt::AlignLeft, "Missing Items" );
        y += 20;
        for ( int i=0; i < _pUI->tblNotCheckedIn->model()->rowCount(); i++ )
        {
            painter.drawText( 20, y, pw, ph, Qt::AlignLeft, _pUI->tblNotCheckedIn->model()->index( i, 1 ).data().toString() );
            y += 20;
        }
    }
    painter.end();
}
开发者ID:JDougherty,项目名称:Fire-Department-Management-System,代码行数:58,代码来源:wndinventorycheck.cpp

示例3: pageSize

void PrinterTests::pageSize()
{
    QPrinter printer;
    printer.setPaperSize(QPrinter::A4);
    printer.setPageMargins(10, 20, 30, 40, QPrinter::Millimeter);
    const QSizeF size = Printer::pageSize(&printer);
    QCOMPARE(size.width(), 1700.0);
    QCOMPARE(size.height(), 2370.0);
}
开发者ID:robcaldecott,项目名称:jupiter,代码行数:9,代码来源:PrinterTests.cpp

示例4: on_printButton_clicked

void PrintDialog::on_printButton_clicked()
{
  QPrinter printer;
  printer.setPageMargins(10.0,10.0,10.0,10.0,printer.Millimeter);
  QPrintDialog *dialog = new QPrintDialog(&printer, this);
  dialog->setWindowTitle(tr("Print Document"));
  if (dialog->exec() != QDialog::Accepted)
    return;
  ui->textEdit->print(&printer);
}
开发者ID:BenZoFly,项目名称:opentx,代码行数:10,代码来源:printdialog.cpp

示例5: print

void Document::print()
{
	QPrinter printer;
	printer.setPageSize(QPrinter::Letter);
	printer.setPageMargins(0.5, 0.5, 0.5, 0.5, QPrinter::Inch);
	QPrintDialog dialog(&printer, this);
	if (dialog.exec() == QDialog::Accepted) {
		m_text->print(&printer);
	}
}
开发者ID:quickhand,项目名称:Prosit,代码行数:10,代码来源:document.cpp

示例6: renderPdf

bool Phantom::renderPdf(const QString &fileName)
{
    QPrinter printer;
    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setOutputFileName(fileName);
    printer.setResolution(PHANTOMJS_PDF_DPI);
    QVariantMap paperSize = m_paperSize;

    if (paperSize.isEmpty()) {
        const QSize pageSize = m_page.mainFrame()->contentsSize();
        paperSize.insert("width", QString::number(pageSize.width()) + "px");
        paperSize.insert("height", QString::number(pageSize.height()) + "px");
        paperSize.insert("border", "0px");
    }

    if (paperSize.contains("width") && paperSize.contains("height")) {
        const QSizeF sizePt(ceil(stringToPointSize(paperSize.value("width").toString())),
                            ceil(stringToPointSize(paperSize.value("height").toString())));
        printer.setPaperSize(sizePt, QPrinter::Point);
    } else if (paperSize.contains("format")) {
        const QPrinter::Orientation orientation = paperSize.contains("orientation")
                && paperSize.value("orientation").toString().compare("landscape", Qt::CaseInsensitive) == 0 ?
                    QPrinter::Landscape : QPrinter::Portrait;
        printer.setOrientation(orientation);
        static const struct {
            QString format;
            QPrinter::PaperSize paperSize;
        } formats[] = {
            { "A3", QPrinter::A3 },
            { "A4", QPrinter::A4 },
            { "A5", QPrinter::A5 },
            { "Legal", QPrinter::Legal },
            { "Letter", QPrinter::Letter },
            { "Tabloid", QPrinter::Tabloid }
        };
        printer.setPaperSize(QPrinter::A4); // Fallback
        for (uint i = 0; i < sizeof(formats) / sizeof(formats[0]); ++i) {
            if (paperSize.value("format").toString().compare(formats[i].format, Qt::CaseInsensitive) == 0) {
                printer.setPaperSize(formats[i].paperSize);
                break;
            }
        }
    } else {
        return false;
    }

    const qreal border = paperSize.contains("border") ?
                floor(stringToPointSize(paperSize.value("border").toString())) : 0;
    printer.setPageMargins(border, border, border, border, QPrinter::Point);

    m_page.mainFrame()->print(&printer);
    return true;
}
开发者ID:10git,项目名称:TheObserver,代码行数:53,代码来源:phantom.cpp

示例7: handlePrint

void CodeEditor::handlePrint()
{
	ENABLED_IF( true );

	QPrinter p;
	p.setPageMargins( 15, 10, 10, 10, QPrinter::Millimeter );

	QPrintDialog dialog( &p, this );
	if( dialog.exec() )
	{
		print( &p );
	}
}
开发者ID:Wushaowei001,项目名称:NAF,代码行数:13,代码来源:CodeEditor.cpp

示例8: print

void Document::print()
{
	QPrinter printer;
	printer.setPageSize(QPrinter::Letter);
	printer.setPageMargins(0.5, 0.5, 0.5, 0.5, QPrinter::Inch);
	QPrintDialog dialog(&printer, this);
	if (dialog.exec() == QDialog::Accepted) {
		bool enabled = m_highlighter->enabled();
		m_highlighter->setEnabled(false);
		m_text->print(&printer);
		if (enabled) {
			m_highlighter->setEnabled(true);
		}
	}
}
开发者ID:rcjavier,项目名称:focuswriter,代码行数:15,代码来源:document.cpp

示例9: on_printFileButton_clicked

void CompareDialog::on_printFileButton_clicked()
{
  QPrinter printer;
  QString filename = QFileDialog::getSaveFileName(this, tr("Select PDF output file"), QString(), "Pdf File(*.pdf)");
  printer.setPageMargins(10.0, 10.0, 10.0, 10.0, printer.Millimeter);
  printer.setOutputFormat(QPrinter::PdfFormat);
  printer.setOrientation(QPrinter::Landscape);
  printer.setColorMode(QPrinter::Color);
  if (!filename.isEmpty()) {
    if (QFileInfo(filename).suffix().isEmpty())
      filename.append(".pdf");
    printer.setOutputFileName(filename);
    ui->textEdit->print(&printer);
  }
}
开发者ID:BenZoFly,项目名称:opentx,代码行数:15,代码来源:comparedialog.cpp

示例10: onActionExportToPdf

/*----------------------------------------------------------------------------*/
void ReportDialog::onActionExportToPdf()
{
  QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
                             "",
                             tr("Pdf files (*.pdf)"));
  if(fileName.isEmpty())
    return;
  QPrinter printer;
  printer.setPaperSize(QPrinter::A4);
  printer.setOrientation(QPrinter::Portrait);
  printer.setPageMargins(20.0,10.0,10.0,10.0,QPrinter::Millimeter);
  printer.setOutputFileName(fileName);
  printer.setOutputFormat(QPrinter::PdfFormat);
  ui->webView->print(&printer);
  printer.newPage();
}
开发者ID:olegyurchenko,项目名称:dda-control,代码行数:17,代码来源:reportwindow.cpp

示例11: printLabel

/*!
  \param itemRow The row of the item for which to print the barcode lable.
  \see printLabelCurrent()
*/
void wndInventoryControl::printLabel( QVector<int> itemRow )
{
    QPrinter printer;

    // The labels used are 2.25"x0.75"
    // Set page size and margins accordingly
    qreal labelwidth = 2.25;
    qreal labelheight = 0.75;
    printer.setPaperSize( QSizeF( labelwidth, labelheight ), QPrinter::Inch );
    printer.setPageMargins( 0, 0, 0, 0, QPrinter::Inch );

    // PDF printing:
    //printer.setOutputFormat(QPrinter::PdfFormat);
    //printer.setOutputFileName("test.pdf");

    // Build the painter data which is printed
    QPainter painter;

    if ( !painter.begin( &printer ) ) // Link the painter to the printer
    {
        qWarning( "Printer Error: Could not link painter to printer." );
        return;
    }

    for ( int i = 0; i < itemRow.size(); i++ )
    {
        // Get the id column of the QTableView.
        QString codestring = "*" + _pUI->tblInventory->model()->data( _pUI->tblInventory->model()->index( itemRow[i] ,0 ) ).toString() + "*";

        // Draw the plaintext id centered at the top of the label
        painter.setFont( QFont( "Verdana", 10 ) );
        painter.drawText( 0 ,0, (int)( labelwidth * printer.resolution() ), (int)( labelheight * printer.resolution() ),
                          Qt::AlignHCenter, codestring );

        // Switch to the barcode font and do the same
        painter.setFont( QFont( "Free 3 of 9 Extended", 32 ) );
        painter.drawText( 0, 15, (int)( labelwidth * printer.resolution() ), (int)( labelheight * printer.resolution() ),
                          Qt::AlignHCenter, codestring );

        if ( i < itemRow.size() - 1 )
            printer.newPage();
    }

    painter.end(); // Send output
}
开发者ID:JDougherty,项目名称:Fire-Department-Management-System,代码行数:49,代码来源:wndinventorycontrol.cpp

示例12: printChecker

void WMain::printChecker()
{
    // Preparing.
    QPrinter printer;
    printer.setOrientation(QPrinter::Landscape);
    QPrintDialog dialog(&printer, this);

    // Setting up margins.
    printer.setPageMargins(12.5, 12.5, 12.5, 12.5, QPrinter::Millimeter);

    // Printing.
    if (dialog.exec() == QDialog::Accepted)
    {
        QPainter painter(&printer);
        painter.drawPixmap(0, 0, checker);
        painter.end();
    }
}
开发者ID:kmingulov,项目名称:JapanTables,代码行数:18,代码来源:WMain.cpp

示例13: printToFile

void PrintDialog::printToFile()
{
  if (printfilename.isEmpty())
    return;
  if (! (printfilename.endsWith(".odt", Qt::CaseInsensitive) || printfilename.endsWith(".pdf", Qt::CaseInsensitive) || printfilename.endsWith(".htm", Qt::CaseInsensitive) || printfilename.endsWith(".html", Qt::CaseInsensitive)) )
    printfilename += ".pdf"; // default
  if (printfilename.endsWith(".pdf", Qt::CaseInsensitive)) {
    QPrinter printer;
    printer.setPageMargins(10.0,10.0,10.0,10.0,printer.Millimeter);
    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setColorMode(QPrinter::Color);
    printer.setOutputFileName(printfilename);
    ui->textEdit->print(&printer);
  }
  else {
    QTextDocumentWriter writer(printfilename);
    writer.write(ui->textEdit->document());
  }
}
开发者ID:BenZoFly,项目名称:opentx,代码行数:19,代码来源:printdialog.cpp

示例14: on_printFileButton_clicked

void PrintDialog::on_printFileButton_clicked()
{
  QString fn = QFileDialog::getSaveFileName(this,tr("Select PDF output file"),QString(),tr("ODF files (*.odt);;PDF Files(*.pdf);;HTML-Files (*.htm *.html);;All Files (*)"));
  if (fn.isEmpty())
    return;
  if (! (fn.endsWith(".odt", Qt::CaseInsensitive) || fn.endsWith(".pdf", Qt::CaseInsensitive) || fn.endsWith(".htm", Qt::CaseInsensitive) || fn.endsWith(".html", Qt::CaseInsensitive)) )
    fn += ".pdf"; // default
  if (fn.endsWith(".pdf", Qt::CaseInsensitive)) {
    QPrinter printer;
    printer.setPageMargins(10.0,10.0,10.0,10.0,printer.Millimeter);
    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setColorMode(QPrinter::Color);
    printer.setOutputFileName(fn);
    ui->textEdit->print(&printer);
  }
  else {
    QTextDocumentWriter writer(fn);
     writer.write(ui->textEdit->document());
  }
}
开发者ID:BenZoFly,项目名称:opentx,代码行数:20,代码来源:printdialog.cpp

示例15: handleExportPdf

void CodeEditor::handleExportPdf()
{
	ENABLED_IF( true );

	QString fileName = QFileDialog::getSaveFileName(this, tr("Export PDF"), QString(), tr("*.pdf") );
	if (fileName.isEmpty())
		return;

	QFileInfo info( fileName );

	if( info.suffix().toUpper() != "PDF" )
		fileName += ".pdf";
	info.setFile( fileName );

	QPrinter p;
	p.setPageMargins( 15, 10, 10, 10, QPrinter::Millimeter );
	p.setOutputFormat(QPrinter::PdfFormat);
	p.setOutputFileName(fileName);

	print( &p );
}
开发者ID:Wushaowei001,项目名称:NAF,代码行数:21,代码来源:CodeEditor.cpp


注:本文中的QPrinter::setPageMargins方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。