sms

prnt

sms
Jan 18th, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void MainWindow::on_print_clicked()
  2. {
  3.     if (template_ptr != Q_NULLPTR) {
  4.         QPrinter printer(QPrinter::HighResolution);
  5.         if (QPrintDialog(&printer, this).exec() == QDialog::Accepted) {
  6.             if (QPageSetupDialog(&printer, this).exec() == QDialog::Accepted) {
  7.                 QPainter painter(&printer);
  8.                 painter.setRenderHint(QPainter::Antialiasing);
  9.                 painter.setRenderHint(QPainter::TextAntialiasing);
  10.                 qreal x, _y, h, w, fake;
  11.                 ui->graphicsView->sceneRect().getRect(&x, &_y, &w, &fake);
  12.                 h = template_ptr->page_height*2.0;
  13.                 qint32 page = 0;
  14.                 while (true) {
  15.                     qreal y = _y + h*page;
  16.                     QRectF leftRect(x, y, w, template_ptr->page_height*2.0*5.0 - h*page);
  17.                     if (ui->graphicsView->scene()->items(leftRect).length() <= 0) {
  18.                         break;
  19.                     }
  20.                     QRectF sourceRect(x, y, w, h);
  21.                     ui->graphicsView->scene()->render(&painter, printer.pageRect(), sourceRect);
  22.                     printer.newPage();
  23.                     page++;
  24.                 }
  25.             }
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment