void addoredir_raspisanie::on_pushButton_print_clicked()
{
    if(ui->comboBox_sotr->currentIndex()==-1)
    {
        return;
    }
    body = "";
    body += "<H2>Расписание " + ui->comboBox_sotr->currentText() + "</H2>";
    body += "<table border=\"1\">";
    body += "<tr><td>Время</td>";
    for (int k = 0; k < days.count(); k++)
        body += "<td align=\"center\" valign = \"middle\" style=\"padding:3px;\"><b>" + days.at(k) + "</b></td>";
    body += "</tr>";

    for (int vr = 1; vr < 7; vr++)
    {
        body += "<tr>";
        body += "<td align=\"center\" valign = \"middle\" style=\"padding:3px;\"><b>" + ui->tableWidget_rasp->item(vr, 0)->text() + "</b></td>";// время
        for (int den = 1; den < 7; den++)
        {
            body += "<td style=\"padding:3px;\">" + ui->tableWidget_rasp->item(vr, den)->text() + "</td>";
        }
        body += "</tr>";
    }
    body += "</table>";
    //    QPrinter printer(QPrinter::HighResolution);
    //    printer.setOrientation(QPrinter::Portrait);
    //    printer.setPaperSize(QPrinter::A4);
    //    printer.setFullPage(true);
    QPrinter printer(QPrinter::HighResolution);
    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setOutputFileName("file.pdf");
    QPrintPreviewDialog  *preview = new QPrintPreviewDialog (&printer);
    preview->setAttribute(Qt::WA_DeleteOnClose);
    preview->setWindowTitle("Печать");
    preview->setWindowFlags(Qt::Window);
    connect(preview, SIGNAL(paintRequested(QPrinter *)), SLOT(printDocument(QPrinter *)));
    preview->exec();
}
Example #2
0
// ---------------------------------------------------------------------
void Editm::cmd(string p,string v)
{
  QStringList opt=qsplit(v);
  if (p=="print") {
#ifndef QT_NO_PRINTER
    ((EditmPTE*) widget)->printPreview(config.Printer);
#endif
  } else if (p=="printpreview") {
#ifndef QT_NO_PRINTER
    QPrintPreviewDialog *dlg = new QPrintPreviewDialog(config.Printer, pform);
    dlg->setWindowTitle("Preview Document");
    QObject::connect(dlg,SIGNAL(paintRequested(QPrinter *)),((EditmPTE*) widget),SLOT(printPreview(QPrinter *)));
    dlg->exec();
    delete dlg;
    config.Printer->setPrintRange(QPrinter::AllPages);
#endif
  } else Child::set(p,v);
Example #3
0
void TextPrinter::preview(const QTextDocument *document,
                          const QString &caption)
{
#if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 0))
    if (!document) return;

    QPrintPreviewDialog *dialog = new QPrintPreviewDialog(printer_, parent_);
    dialog->setWindowTitle(caption.isEmpty() ? "Print Preview" : caption);

    connect(dialog, SIGNAL(paintRequested(QPrinter*)),
            this, SLOT(print(QPrinter*)));

    // preview it
    tempdoc_ = document->clone();
    dialog->exec();

    delete tempdoc_;
    tempdoc_ = 0;

    delete dialog;
#endif
}