Trying to render from a QGraphicsScene to a printer...
-
Trying to render a scene to a printer via a painter...
The scene gets populated and displays at the .show. in the QGraphicsView widget on the ui form.
The print dialog opens, allowing a printer to be selected.
A blank sheet is all that is output.
Not sure what I'm doing wrong. Tried googling and forum searching for examples on how to do this. The docs have "examples" but are pretty simplistic.
Any help would be appreciated.
@
void frmSightTape::on_pbTest_clicked()
{QString filePath = QApplication::applicationDirPath() + "/Graphics/";
QFont sceneFont("Arial", 10, QFont::Bold);
qreal pdpi = 600;
QGraphicsScene scene = new QGraphicsScene(0,0,pdpi8.5,pdpi*11.0);QGraphicsPixmapItem *tape = new QGraphicsPixmapItem(0,0);
tape->setPixmap( QPixmap(filePath + "tmpTapeScaled.png",0,Qt::AutoColor ));tape->setPos(100,100);
tape->setScale( 1 );
scene->addItem( tape );QGraphicsTextItem *bla = new QGraphicsTextItem( "bla bla bla",0,0);
bla->setPos( 20,20 );
scene->addItem( bla );// gvTapeSheet is a QGraphicsView on a ui form
ui->gvTapeSheet->setScene( scene );
ui->gvTapeSheet->show();// the tape sheet changes to reflect the items added
QPrinter printer(QPrinter::HighResolution);
//printer.setPaperSize(QPrinter::Letter);
printer.setPageSize(QPrinter::Letter);QPrintDialog *printDialog = new QPrintDialog(&printer, this);
if (printDialog->exec() == QDialog::Accepted)
{QPainter painter(&printer); painter.setRenderHint(QPainter::Antialiasing); #if DEBUG_PRINT qDebug() << "-on_pbTest: scene w=" << scene->sceneRect().width() << " h=" << scene->sceneRect().height(); qDebug() << "-on_pbTest: printer " << printer.paperRect(); qDebug() << "-on_pbTest: printer " << printer.resolution(); #endif scene->render(&painter,scene->sceneRect(),printer.paperRect(),Qt::KeepAspectRatio); //scene->render(&painter); //ui->gvLabelSheet->scene()->render(&painter,ui->gvLabelSheet->scene()->sceneRect(),printer.paperRect(),Qt::KeepAspectRatio); //ui->gvLabelSheet->scene()->render(&painter); painter.end();
}
}
@
debug output is..
-on_pbTest: scene w= 5100 h= 6600
-on_pbTest: printer QRect(0,0 5100x6600)
-on_pbTest: printer 600