本文整理汇总了C++中QTextDocument::print方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextDocument::print方法的具体用法?C++ QTextDocument::print怎么用?C++ QTextDocument::print使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextDocument
的用法示例。
在下文中一共展示了QTextDocument::print方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: slotPrintPreview
void CDiaryEdit::slotPrintPreview()
{
CDiaryEditLock lock(this);
collectData();
QPrinter printer;
QPrintDialog dialog(&printer, this);
dialog.setWindowTitle(tr("Print Diary"));
if (dialog.exec() != QDialog::Accepted)
return;
QTextDocument doc;
QSizeF pageSize = printer.pageRect(QPrinter::DevicePixel).size();
doc.setPageSize(pageSize);
draw(doc);
if(checkAddMap->isChecked())
{
QImage img;
theMainWindow->getCanvas()->print(img, pageSize.toSize() - QSize(10,10));
doc.rootFrame()->lastCursorPosition().insertImage(img);
}
doc.print(&printer);
textEdit->clear();
textEdit->document()->setTextWidth(textEdit->size().width() - 20);
draw(*textEdit->document());
}
示例2: openPrintDialog
void EditDialog::openPrintDialog()
{
QPrinter printer;
QPrintPreviewDialog *dialog = new QPrintPreviewDialog(&printer);
QTextDocument *document = new QTextDocument();
switch (dataSource) {
case TextBuffer:
document->setPlainText(ui->editorText->toPlainText());
break;
case SciBuffer:
// This case isn't really expected because the Scintilla widget has it's own printing slot
document->setPlainText(sciEdit->text());
break;
case HexBuffer:
document->setPlainText(hexEdit->toReadableString());
document->setDefaultFont(hexEdit->font());
break;
}
connect(dialog, &QPrintPreviewDialog::paintRequested, [&](QPrinter *previewPrinter) {
document->print(previewPrinter);
});
dialog->exec();
delete dialog;
delete document;
}
示例3: print
/**
* Methode permettant d'imprimer un document
*/
void ValidDocument::print(){
QWebView webView;
QPrinter printer ;
printer.setPageSize(QPrinter::A4);
printer.setFullPage(true);
QString type=(docType==Document::Facture)?QObject::trUtf8("Facture"):QObject::trUtf8("Devis");
printer.setDocName(type+"_"+QString::number(id) );
printer.setCreator(QObject::trUtf8("QFacturation"));
printer.setOutputFormat(QPrinter::NativeFormat);
webView.setHtml(view);
webView.show();
QPrintDialog printDialog(&printer);
if(printDialog.exec() == QDialog::Accepted) {
qDebug("Ne fonctionne pas sous windows")<<" Hack ....";
#if defined(Q_WS_WIN)
QTextDocument text;
text.setHtml(view);
text.print(&printer);
#endif
#if defined(Q_WS_QWS)
webView.print(&printer);
#endif
#if defined(Q_WS_X11)
webView.print(&printer);
#endif
}
}
示例4: print
bool ignsystem::print(const QVariant &config){
QVariantMap conf = jsonParse->jsonParser(config).toVariantMap();
QPrinter print;
QTextDocument *doc = new QTextDocument();
QString type = conf["type"].toString();
QString txt = conf["content"].toString();
QString out = conf["out"].toString();
if(type == "html")
{
doc->setHtml(txt);
}
else
{
doc->setPlainText(txt);
}
if(out == "pdf"){
print.setOutputFormat(QPrinter::PdfFormat);
}
QPrintDialog *dialog = new QPrintDialog(&print);
if (dialog->exec() != QDialog::Accepted)
{
return false;
}
else
{
doc->print(&print);
delete doc;
return true;
}
}
示例5: printMapScreenShot
void ControlView::printMapScreenShot( QPointer<QPrintDialog> printDialog)
{
#ifndef QT_NO_PRINTER
PrintOptionsWidget* printOptions = new PrintOptionsWidget( this );
bool const mapCoversViewport = m_marbleWidget->viewport()->mapCoversViewport();
printOptions->setBackgroundControlsEnabled( !mapCoversViewport );
bool hasLegend = m_marbleWidget->model()->legend() != 0;
printOptions->setLegendControlsEnabled( hasLegend );
bool hasRoute = marbleWidget()->model()->routingManager()->routingModel()->rowCount() > 0;
printOptions->setPrintRouteSummary( hasRoute );
printOptions->setPrintDrivingInstructions( hasRoute );
printOptions->setPrintDrivingInstructionsAdvice( hasRoute );
printOptions->setRouteControlsEnabled( hasRoute );
printDialog->setOptionTabs( QList<QWidget*>() << printOptions );
if ( printDialog->exec() == QDialog::Accepted ) {
QTextDocument document;
QString text = "<html><head><title>Marble Printout</title></head><body>";
QPalette const originalPalette = m_marbleWidget->palette();
bool const wasBackgroundVisible = m_marbleWidget->showBackground();
bool const hideBackground = !mapCoversViewport && !printOptions->printBackground();
if ( hideBackground ) {
// Temporarily remove the black background and layers painting on it
m_marbleWidget->setShowBackground( false );
m_marbleWidget->setPalette( QPalette ( Qt::white ) );
m_marbleWidget->update();
}
if ( printOptions->printMap() ) {
printMap( document, text, printDialog->printer() );
}
if ( printOptions->printLegend() ) {
printLegend( document, text );
}
if ( printOptions->printRouteSummary() ) {
printRouteSummary( document, text );
}
if ( printOptions->printDrivingInstructions() ) {
printDrivingInstructions( document, text );
}
if ( printOptions->printDrivingInstructionsAdvice() ) {
printDrivingInstructionsAdvice( document, text );
}
text += "</body></html>";
document.setHtml( text );
document.print( printDialog->printer() );
if ( hideBackground ) {
m_marbleWidget->setShowBackground( wasBackgroundVisible );
m_marbleWidget->setPalette( originalPalette );
m_marbleWidget->update();
}
}
#endif
}
示例6: doPrintParameterStatistic
void MainWindow::doPrintParameterStatistic()
{
if ( gv_PS.count() > 0 )
{
QTextDocument textDocu;
QPrinter printer;
QPrintDialog printDialog( &printer, this );
printer.setOrientation( QPrinter::Landscape );
if ( printDialog.exec() == QDialog::Accepted )
{
QFileInfo fi( gsl_FilenameList.at( 0 ) );
QFont textFont = QFont( gf_HeaderTextFont.family(), 10, 0, false );
printer.setOutputFileName( tr( "" ) );
textDocu.setHtml( createParameterStatisticOutputText( fi.fileName(), gv_PS ) );
textDocu.setDefaultFont( textFont );
textDocu.print( &printer );
}
update();
}
setStatusBar( tr( "Done" ), 2 );
}
示例7: print
bool ignsystem::print(const QVariant &config) {
QVariantMap configuration = jsonParse->jsonParser(config).toVariantMap();
QPrinter printer;
QTextDocument *document = new QTextDocument();
QPrintDialog *printDialog = new QPrintDialog(&printer);
QString type = configuration[QStringLiteral("type")].toString();
QString content = configuration[QStringLiteral("content")].toString();
QString output = configuration[QStringLiteral("out")].toString();
if (type == QLatin1String("html")) {
document->setHtml(content);
} else {
document->setPlainText(content);
}
if (output == QLatin1String("pdf")) {
printer.setOutputFormat(QPrinter::PdfFormat);
}
if (printDialog->exec() == QDialog::Accepted) {
document->print(&printer);
delete document;
return true;
} else {
return false;
}
}
示例8: printAllClick
//Print clicked, format all lists
//for printing
void TaskList_Main::printAllClick(){
QPrinter printer;
//Create new print dialog (select printer)
QPrintDialog *pDialog = new QPrintDialog(&printer, this);
pDialog->setWindowTitle(tr("Print Document"));
if(pDialog->exec() != QDialog::Accepted)
return;
else{
QTextDocument document;
QString html = "";
for(int i = 0; i < listPane->mainList->count(); ++i){
QListWidgetItem *currList = listPane->mainList->item(i);
my_listwidget *currNote = notePane->listMap[currList];
//Generate HTML driven output
html += "<font size=\"7\"><b>" + currList->text() + "</b></font><br />";
for(int i = 0; i < currNote->count(); i++){
if(currNote->item(i)->flags() != 0)
html += "<font size=\"5\">" + currNote->item(i)->text() + "</font><br />";
else
html += "--<font size=\"4\"><i>" + currNote->item(i)->text() + "</i></font><br />";
}
html += "<br />";
}
//Set document's HTML info
document.setHtml(html);
//Print the HTML text
document.print(&printer);
}
}
示例9: printDeckList
void DeckListModel::printDeckList(QPrinter *printer)
{
QTextDocument doc;
QFont font("Serif");
font.setStyleHint(QFont::Serif);
doc.setDefaultFont(font);
QTextCursor cursor(&doc);
QTextBlockFormat headerBlockFormat;
QTextCharFormat headerCharFormat;
headerCharFormat.setFontPointSize(16);
headerCharFormat.setFontWeight(QFont::Bold);
cursor.insertBlock(headerBlockFormat, headerCharFormat);
cursor.insertText(deckList->getName());
headerCharFormat.setFontPointSize(12);
cursor.insertBlock(headerBlockFormat, headerCharFormat);
cursor.insertText(deckList->getComments());
cursor.insertBlock(headerBlockFormat, headerCharFormat);
for (int i = 0; i < root->size(); i++) {
cursor.insertHtml("<br><img src=:/resources/hr.jpg>");
//cursor.insertHtml("<hr>");
cursor.insertBlock(headerBlockFormat, headerCharFormat);
printDeckListNode(&cursor, dynamic_cast<InnerDecklistNode *>(root->at(i)));
}
doc.print(printer);
}
示例10: on_toolButton_print_clicked
void PringKvitok::on_toolButton_print_clicked()
{
#if !defined(QT_NO_PRINTER)
QPrinter printer(QPrinter::HighResolution);
QPrintDialog *dlg = new QPrintDialog(&printer, this);
dlg->setWindowTitle(tr("Настройки принтера"));
if (dlg->exec() == QDialog::Accepted){
QString pg;
QMapIterator<QString, QCheckBox*> i(childsCheckBox_map);
ui->progressBar->setVisible(true);
int count = 0;
int c = 0;
while (i.hasNext()) {
i.next();
QCheckBox *cb = i.value();
if (cb->checkState() == Qt::Checked){
count++;
}
}
ui->progressBar->setMaximum(count);
QString page1;
QString page2;
while (i.hasPrevious()) {
i.previous();
QCheckBox *cb = i.value();
if (cb->checkState() == Qt::Checked){
if (ui->checkBox_twokv->checkState() == Qt::Checked){
if (page1 == "") page1 = prepareKvit(cb->text());
else {
page2 = prepareKvit(cb->text());
pg += TwoKvitOnePage(page1, page2);
page1 = "";
page2 = "";
}
} else pg += prepareKvit(cb->text());
ui->progressBar->setValue(c++);
}
}
if (ui->checkBox_twokv->checkState() == Qt::Checked && page1 != "" && page2 == "") pg += page1;
QTextDocument textDocument;
textDocument.setHtml(pg);
QPrinter printer(QPrinter::HighResolution);
printer.setOrientation(QPrinter::Portrait);
printer.setPaperName("A4");
printer.setPageMargins(0.3, 0.3, 0.3, 0.3, QPrinter::Unit() );
if (ui->checkBox_duplex->checkState() == Qt::Checked)printer.setDuplex(QPrinter::DuplexAuto);
textDocument.print(&printer);
ui->progressBar->setVisible(false);
}
delete dlg;
#endif
}
示例11: printTable
void PrintLayout::printTable() const
{
QTextDocument doc;
QSizeF pageSize;
pageSize.setWidth(pageRect.width());
pageSize.setHeight(pageRect.height());
doc.setPageSize(pageSize);
QString styleSheet(
"<style type='text/css'>" \
"table {" \
" border-width: 1px;" \
" border-style: solid;" \
" border-color: #999999;" \
"}" \
"th {" \
" background-color: #eeeeee;" \
" font-size: small;" \
" padding: 3px 5px 3px 5px;" \
"}" \
"td {" \
" font-size: small;" \
" padding: 3px 5px 3px 5px;" \
"}" \
"</style>"
);
// setDefaultStyleSheet() doesn't work here?
QString htmlText = styleSheet + "<table cellspacing='0' width='100%'>";
QString htmlTextPrev;
int pageCountNew = 1, pageCount;
bool insertHeading = true;
int i;
struct dive *dive;
for_each_dive(i, dive) {
if (!dive->selected && printOptions->print_selected)
continue;
if (insertHeading) {
htmlText += insertTableHeadingRow();
insertHeading = false;
}
htmlTextPrev = htmlText;
htmlText += insertTableDataRow(dive);
doc.setHtml(htmlText);
pageCount = pageCountNew;
pageCountNew = doc.pageCount();
/* if the page count increases after adding this row we 'revert'
* and add a heading instead. */
if (pageCountNew > pageCount) {
htmlText = htmlTextPrev;
insertHeading = true;
i--;
}
}
htmlText += "</table>";
doc.setHtml(htmlText);
doc.print(printer);
}
示例12: on_toolButton_pdf_clicked
void PringKvitok::on_toolButton_pdf_clicked()
{
#if !defined(QT_NO_PRINTER)
QString pg;
QMapIterator<QString, QCheckBox*> i(childsCheckBox_map);
ui->progressBar->setVisible(true);
int count = 0;
int c = 0;
while (i.hasNext()) {
i.next();
QCheckBox *cb = i.value();
if (cb->checkState() == Qt::Checked){
count++;
}
}
ui->progressBar->setMaximum(count);
QString page1;
QString page2;
while (i.hasPrevious()) {
i.previous();
QCheckBox *cb = i.value();
if (cb->checkState() == Qt::Checked){
if (ui->checkBox_twokv->checkState() == Qt::Checked){
if (page1 == "") page1 = prepareKvit(cb->text());
else {
page2 = prepareKvit(cb->text());
pg += TwoKvitOnePage(page1, page2);
page1 = "";
page2 = "";
}
} else pg += prepareKvit(cb->text());
ui->progressBar->setValue(c++);
}
}
if (ui->checkBox_twokv->checkState() == Qt::Checked && page1 != "" && page2 == "") pg += page1;
QTextDocument textDocument;
textDocument.setHtml(pg);
QPrinter printer(QPrinter::HighResolution);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName( "print.pdf");
printer.setOrientation(QPrinter::Portrait);
printer.setPaperName("A4");
printer.setPageMargins(1, 1, 1, 1, QPrinter::Millimeter );
textDocument.print(&printer);
ui->progressBar->setValue(c++);
ui->progressBar->setVisible(false);
#endif
}
示例13: printer
void MainWindow::on_pushButton_4_clicked()
{
QTextDocument doc;
QString txt;
txt = ::textAt(h3,65,"ASAP Film Order") %
::textAt(h3,40,"From C&C Special Products Co. 952-881-0073") %
::textAt(h3,67,"Mark Robin") %
::textAt(h3,6,"Attn: Customer Service") % ::nbsp(63) % "Rip Settings:"%
::textAt(h3,103,"1) Film Positives") %
::textAt(h3,103,"2) DO NOT TRAP") %
::textAt(h3,103,"3) Send Pre Separated") %
::textAt(h3,6,"Date: " % ui->dateEdit->text()) %
::textAt(h3,6,"File Name: " % ui->lineEdit_2->text());
qDebug() << "The memory used is: " << txt.capacity();
doc.setHtml(txt);
#if !defined(QT_NO_PRINTER) && !defined(QT_NO_PRINTDIALOG)
QPrinter printer(QPrinter::HighResolution);
QPrintDialog *dlg = new QPrintDialog(&printer, this);
dlg->addEnabledOption(QAbstractPrintDialog::PrintSelection);
dlg->setWindowTitle(tr("Print Document"));
if (dlg->exec() == QDialog::Accepted)
{
QPrinter printer;
// printer.setOutputFileName("c:\\temp\\filenew.pdf");
// printer.setOutputFormat(QPrinter::PdfFormat);
qDebug() << "Sending to printer";
doc.print(&printer);
printer.newPage();
printer.setOutputFileName("c:\\temp\\faxASAP.pdf");
printer.setOutputFormat(QPrinter::PdfFormat);
qDebug() << "Creating PDF";
doc.print(&printer);
printer.newPage();
}
delete dlg;
#endif
}
示例14: printThreadFunc
/**
* Статическая функция печати текстового документа. Может выполняться в
* отдельном потоке.
*
* @param qdoc - указатель на текстовый документ, приготовленный к печати.
* @param printer - указатель на объект принтера.
*/
void MonitorWindow::printThreadFunc(QTextDocument * qdoc, QPrinter * printer)
{
QTextDocument * doc = qdoc->clone();
//QTime time;
//time.start();
doc->print(printer);
//qDebug() << time.elapsed();
}
示例15: printHtml
void Print::printHtml(const QString &html){
QPrinter printer;
QPrintDialog printDialog(&printer);
if(printDialog.exec()){
QTextDocument textDocument;
textDocument.setHtml(html);
textDocument.print(&printer);
}
}