本文整理汇总了C++中QPrinter::setResolution方法的典型用法代码示例。如果您正苦于以下问题:C++ QPrinter::setResolution方法的具体用法?C++ QPrinter::setResolution怎么用?C++ QPrinter::setResolution使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPrinter
的用法示例。
在下文中一共展示了QPrinter::setResolution方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exportVector
void Matrix::exportVector(const QString& fileName, int res, bool color)
{
if ( fileName.isEmpty() ){
QMessageBox::critical(this, tr("QtiPlot - Error"), tr("Please provide a valid file name!"));
return;
}
QPrinter printer;
printer.setCreator("QtiPlot");
printer.setFullPage(true);
if (res)
printer.setResolution(res);
printer.setOutputFileName(fileName);
if (fileName.contains(".eps"))
printer.setOutputFormat(QPrinter::PostScriptFormat);
if (color)
printer.setColorMode(QPrinter::Color);
else
printer.setColorMode(QPrinter::GrayScale);
printer.setOrientation(QPrinter::Portrait);
int cols = numCols();
int rows = numRows();
QRect rect = QRect(0, 0, cols, rows);
printer.setPaperSize(QSizeF(cols, rows), QPrinter::DevicePixel);
QPainter paint(&printer);
paint.drawImage(rect, d_matrix_model->renderImage());
paint.end();
}
示例2: exportToEPS
void MultiLayer::exportToEPS(const QString& fname, int res, QPrinter::Orientation o,
QPrinter::PageSize pageSize, QPrinter::ColorMode col)
{
QPrinter printer;
printer.setResolution(res);
printer.setPageSize(pageSize);
printer.setColorMode(col);
printer.setOrientation(o);
printer.setFullPage(TRUE);
printer.setOutputToFile (TRUE);
printer.setOutputFileName(fname);
QPainter paint(&printer);
QPaintDeviceMetrics pdmTo(&printer);
int dpiy = pdmTo.logicalDpiY();
int margin = (int) ( (0.5/2.54)*dpiy ); // 5 mm margins
QSize size = canvas->size();
double scaleFactorX=(double)(pdmTo.width() - 2*margin)/(double)size.width();
double scaleFactorY=(double)(pdmTo.height() - 2*margin)/(double)size.height();
for (int i=0;i<(int)graphsList->count();i++)
{
Graph *gr=(Graph *)graphsList->at(i);
Plot *myPlot= (Plot *)gr->plotWidget();
PrintFilter filter(myPlot);
filter.setOptions(QwtPlotPrintFilter::PrintAll | QwtPlotPrintFilter::PrintTitle
| QwtPlotPrintFilter::PrintCanvasBackground);
QPoint pos=gr->pos();
pos=QPoint(int(margin + pos.x()*scaleFactorX),int(margin + pos.y()*scaleFactorY));
int width=int(myPlot->frameGeometry().width()*scaleFactorX);
int height=int(myPlot->frameGeometry().height()*scaleFactorY);
QRect rect = QRect(pos,QSize(width,height));
if (myPlot->paletteBackgroundColor() != QColor(white))
paint.fillRect(rect, myPlot->paletteBackgroundColor());
int lw = myPlot->lineWidth();
if ( lw > 0)
{
myPlot->printFrame(&paint, rect);
rect.moveBy ( lw, lw);
rect.setWidth(rect.width() - 2*lw);
rect.setHeight(rect.height() - 2*lw);
}
myPlot->print(&paint, rect, filter);
}
if (hasOverlapingLayers())
updateTransparency();
}
示例3: beginPrint
void QgsComposition::beginPrint( QPrinter &printer )
{
//set resolution based on composer setting
printer.setFullPage( true );
printer.setColorMode( QPrinter::Color );
//set user-defined resolution
printer.setResolution( printResolution() );
}
示例4: setupPdfPrinter
void SchedulePrintDialog::setupPdfPrinter( QPrinter & printer )
{
printer.setOutputFormat( QPrinter::PdfFormat );
setupPrinter(printer);
printer.setFullPage( true );
printer.setResolution( mDpiSpin->value() );
printer.setFontEmbeddingEnabled(false);
}
示例5: image
void OpenInfraPlatform::UserInterface::Alignment2DScene::exportToFile(QWidget* parent)
{
QString filter;
QString fn = QFileDialog::getSaveFileName(parent, tr("Save Vertical Alignment as..."), QString(), tr("PNG File (*.png);; JPG File (*.jpg);; PDF File (*.pdf);; SVG File (*.svg)"), &filter);
if(fn.isEmpty())
return;
if(filter == "PNG File (*.png)" || filter == "JPG File (*.jpg)")
{
QImage image(sceneRect().size().toSize(), QImage::Format::Format_ARGB32);
image.fill(Qt::darkGray);
QPainter painter(&image);
painter.setRenderHints(QPainter::Antialiasing);
render(&painter);
image.save(fn);
}
else
{
QPrinter printer;
QSvgGenerator svgGen;
QPaintDevice* device;
if(filter == "PDF File (*.pdf)")
{
printer.setResolution(QPrinter::HighResolution);
printer.setPageSize( QPrinter::A4 );
printer.setOrientation( QPrinter::Landscape );
printer.setOutputFormat( QPrinter::PdfFormat );
printer.setOutputFileName(fn);
device = &printer;
}
else if(filter == "SVG File (*.svg)")
{
QRectF rect = sceneRect();
svgGen.setFileName(fn);
svgGen.setSize(QSize(rect.width(),rect.height()));
svgGen.setViewBox(QRect(0,0,rect.width(),rect.height()));
svgGen.setTitle("Vertical Alignment");
device = &svgGen;
}
else
{
return;
}
QPainter painter(device);
configureColors(A2D_DrawState::A2D_Print);
render(&painter);
configureColors(A2D_DrawState::A2D_Draw);
}
}
示例6: saveOverlayPdf
void UBExportFullPDF::saveOverlayPdf(UBDocumentProxy* pDocumentProxy, const QString& filename)
{
if (!pDocumentProxy || filename.length() == 0 || pDocumentProxy->pageCount() == 0)
return;
//PDF
qDebug() << "exporting document to PDF Merger" << filename;
QPrinter pdfPrinter;
pdfPrinter.setOutputFormat(QPrinter::PdfFormat);
pdfPrinter.setResolution(UBSettings::settings()->pdfResolution->get().toInt());
pdfPrinter.setOutputFileName(filename);
pdfPrinter.setFullPage(true);
QPainter* pdfPainter = 0;
for(int pageIndex = 0 ; pageIndex < pDocumentProxy->pageCount(); pageIndex++)
{
UBGraphicsScene* scene = UBPersistenceManager::persistenceManager()->loadDocumentScene(pDocumentProxy, pageIndex);
// set background to white, no grid for PDF output
bool isDark = scene->isDarkBackground();
bool isCrossed = scene->isCrossedBackground();
scene->setBackground(false, false);
// set high res rendering
scene->setRenderingQuality(UBItem::RenderingQualityHigh);
scene->setRenderingContext(UBGraphicsScene::PdfExport);
QSize pageSize = scene->nominalSize();
UBGraphicsPDFItem *pdfItem = qgraphicsitem_cast<UBGraphicsPDFItem*>(scene->backgroundObject());
if (pdfItem) mHasPDFBackgrounds = true;
pdfPrinter.setPaperSize(QSizeF(pageSize.width()*mScaleFactor, pageSize.height()*mScaleFactor), QPrinter::Point);
if (!pdfPainter) pdfPainter = new QPainter(&pdfPrinter);
if (pageIndex != 0) pdfPrinter.newPage();
//render to PDF
scene->setDrawingMode(true);
scene->render(pdfPainter, QRectF(), scene->normalizedSceneRect());
//restore screen rendering quality
scene->setRenderingContext(UBGraphicsScene::Screen);
scene->setRenderingQuality(UBItem::RenderingQualityNormal);
//restore background state
scene->setDrawingMode(false);
scene->setBackground(isDark, isCrossed);
}
if (pdfPainter) delete pdfPainter;
}
示例7: persistsDocument
bool UBExportPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, const QString& filename)
{
QPrinter pdfPrinter;
qDebug() << "exporting document to PDF" << filename;
pdfPrinter.setOutputFormat(QPrinter::PdfFormat);
pdfPrinter.setResolution(UBSettings::settings()->pdfResolution->get().toInt());
pdfPrinter.setOutputFileName(filename);
pdfPrinter.setFullPage(true);
//need to calculate screen resolution
QDesktopWidget* desktop = UBApplication::desktop();
int dpiCommon = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2;
float scaleFactor = 72.0f / dpiCommon;
QPainter pdfPainter;
bool painterNeedsBegin = true;
int existingPageCount = pDocumentProxy->pageCount();
for(int pageIndex = 0 ; pageIndex < existingPageCount; pageIndex++)
{
UBGraphicsScene* scene = UBPersistenceManager::persistenceManager()->loadDocumentScene(pDocumentProxy, pageIndex);
UBApplication::showMessage(tr("Exporting page %1 of %2").arg(pageIndex + 1).arg(existingPageCount));
// set background to white, no crossing for PDF output
bool isDark = scene->isDarkBackground();
bool isCrossed = scene->isCrossedBackground();
scene->setBackground(false, false);
QSize pageSize = scene->nominalSize();
// set high res rendering
scene->setRenderingQuality(UBItem::RenderingQualityHigh);
scene->setRenderingContext(UBGraphicsScene::NonScreen);
//setting page size to appropriate value
pdfPrinter.setPaperSize(QSizeF(pageSize.width()*scaleFactor, pageSize.height()*scaleFactor), QPrinter::Point);
if(painterNeedsBegin) painterNeedsBegin = !pdfPainter.begin(&pdfPrinter);
//render to PDF
scene->render(&pdfPainter, QRectF(), scene->normalizedSceneRect());
if (pageIndex < existingPageCount - 1) pdfPrinter.newPage();
//restore screen rendering quality
scene->setRenderingContext(UBGraphicsScene::Screen);
scene->setRenderingQuality(UBItem::RenderingQualityNormal);
//restore background state
scene->setBackground(isDark, isCrossed);
}
if(!painterNeedsBegin) pdfPainter.end();
return true;
}
示例8: 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;
}
示例9: on_actionPrint_triggered
void MainWindow::on_actionPrint_triggered(bool)
{
//no nothing without images
if (images_.count()==0) return;
QPrinter printer;
printer.setResolution(180);
printer.setPaperSize(QPrinter::A4);
printer.setOrientation(QPrinter::Portrait);
QPrintPreviewDialog dlg(&printer, this);
dlg.setWindowFlags ( Qt::Window );
connect(&dlg, SIGNAL(paintRequested(QPrinter*)), SLOT(printPreview(QPrinter *)));
if(dlg.exec() == QDialog::Rejected) return;
}
示例10: print
void MultiLayer::print()
{
QPrinter printer;
printer.setResolution(84);
printer.setOrientation(QPrinter::Landscape);
printer.setColorMode (QPrinter::Color);
printer.setFullPage(TRUE);
if (printer.setup())
{
QPainter paint(&printer);
printAllLayers(&paint);
paint.end();
}
}
示例11: sizeMM
void
MSPeaksWnd::handlePrintCurrentView( const QString& pdfname )
{
// A4 := 210mm x 297mm (8.27 x 11.69 inch)
QSizeF sizeMM( 260, 160 ); // 260x160mm
int resolution = 300;
const double mmToInch = 1.0 / 25.4;
const QSizeF size = sizeMM * mmToInch * resolution;
double margin_left = 0.2 /* inch */ * resolution;
//double margin_right = ( 8.27 - 0.2 ) * resolution;
//double margin_center = (margin_right - margin_left) / 2 + margin_left;
QPrinter printer;
printer.setColorMode( QPrinter::Color );
printer.setPaperSize( QPrinter::A4 );
printer.setFullPage( false );
printer.setOrientation( QPrinter::Landscape );
printer.setDocName( "QtPlatz MS Peaks" );
printer.setOutputFileName( pdfname );
printer.setResolution( resolution );
//--------------------
QPainter painter( &printer );
int n = 0;
for ( auto& plot: plots_ ) {
QRectF boundingRect;
QRectF drawRect( margin_left, 0.0, printer.width() / 2.0, printer.height() );
if ( n++ & 01 ) {
drawRect.moveLeft( printer.width() / 2.0 );
painter.drawText( drawRect, Qt::TextWordWrap, "Relationship between time and flight length", &boundingRect );
} else {
painter.drawText( drawRect, Qt::TextWordWrap, "Relationship between time and m/z", &boundingRect );
}
QwtPlotRenderer renderer;
renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasBackground, true );
renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasFrame, true );
renderer.setDiscardFlag( QwtPlotRenderer::DiscardBackground, true );
drawRect.setTop( boundingRect.bottom() );
drawRect.setHeight( size.height() );
drawRect.setWidth( size.width() / 2 );
renderer.render( plot.get(), &painter, drawRect ); // render plot
}
}
示例12: print
void QgsComposition::print( QPrinter &printer )
{
//set resolution based on composer setting
printer.setFullPage( true );
printer.setColorMode( QPrinter::Color );
//set user-defined resolution
printer.setResolution( printResolution() );
QPainter p( &printer );
//QgsComposition starts page numbering at 0
int fromPage = ( printer.fromPage() < 1 ) ? 0 : printer.fromPage() - 1 ;
int toPage = ( printer.toPage() < 1 ) ? numPages() - 1 : printer.toPage() - 1;
if ( mPrintAsRaster )
{
for ( int i = fromPage; i <= toPage; ++i )
{
if ( i > fromPage )
{
printer.newPage();
}
QImage image = printPageAsRaster( i );
if ( !image.isNull() )
{
QRectF targetArea( 0, 0, image.width(), image.height() );
p.drawImage( targetArea, image, targetArea );
}
}
}
if ( !mPrintAsRaster )
{
for ( int i = fromPage; i <= toPage; ++i )
{
if ( i > fromPage )
{
printer.newPage();
}
renderPage( &p, i );
}
}
}
示例13: printQuickPCs
void keyPrograms_form::printQuickPCs() {
QPrinter *printer = new QPrinter();
printer->setOrientation( QPrinter::Portrait );
printer->setResolution( 600 );
// printer->setOutputFormat( QPrinter::PostScriptFormat );
QPrintDialog *dialog = new QPrintDialog( printer, this );
dialog->setWindowTitle( tr( "Print EWI Quick Patch Changes" ) );
if ( dialog->exec() != QDialog::Accepted ) return;
// Create a QPainter object to draw on the printer
QPainter p( printer );
QPixmap pm;
pm = QPixmap::grabWidget( this ).scaledToWidth( printer->width() );
p.drawPixmap( 0, 0, pm );
//p.rotate( 90.0 );
p.end();
}
示例14: filePrint
void TextEdit::filePrint()
{
if ( !currentEditor() )
return;
#ifndef QT_NO_PRINTER
QPrinter printer;
printer.setFullPage(TRUE);
QPaintDeviceMetrics screen( this );
printer.setResolution( screen.logicalDpiY() );
if ( printer.setup( this ) ) {
QPainter p( &printer );
QPaintDeviceMetrics metrics( p.device() );
int dpix = metrics.logicalDpiX();
int dpiy = metrics.logicalDpiY();
const int margin = 72; // pt
QRect body( margin * dpix / 72, margin * dpiy / 72,
metrics.width() - margin * dpix / 72 * 2,
metrics.height() - margin * dpiy / 72 * 2 );
QFont font( "times", 10 );
QSimpleRichText richText( currentEditor()->text(), font, currentEditor()->context(), currentEditor()->styleSheet(),
currentEditor()->mimeSourceFactory(), body.height() );
richText.setWidth( &p, body.width() );
QRect view( body );
int page = 1;
do {
richText.draw( &p, body.left(), body.top(), view, colorGroup() );
view.moveBy( 0, body.height() );
p.translate( 0 , -body.height() );
p.setFont( font );
p.drawText( view.right() - p.fontMetrics().width( QString::number( page ) ),
view.bottom() + p.fontMetrics().ascent() + 5, QString::number( page ) );
if ( view.top() >= richText.height() )
break;
printer.newPage();
page++;
} while (TRUE);
}
#endif
}
示例15: on_pushButton_clicked
void MainWindow::on_pushButton_clicked()
{
int current_tab = this->ui->tabWidget->currentIndex();
QPrinter printer;
QTableView *myWidget;
switch(current_tab)
{
case TABLE::StudentsTableTab:
myWidget = this->ui->StudentsTableView;
break;
case TABLE::TeachersTableTab:
myWidget = this->ui->TeachersTableView;
break;
default:
return;
}
QPixmap pix = myWidget->grab();
QPainter painter;
printer.setResolution(QPrinter::HighResolution);
printer.setPageMargins (15,15,15,15,QPrinter::Millimeter);
painter.begin(&printer);
double xscale = printer.pageRect().width()/double(myWidget->width() + 50);
double yscale = printer.pageRect().height()/double(myWidget->height() + 50);
double scale = qMin(xscale, yscale);
painter.scale(scale, scale);
painter.drawPixmap(0, 0, pix);
painter.end();
myWidget->render(&painter);
}