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->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 );

    // the tape sheet changes to reflect the items added

    QPrinter printer(QPrinter::HighResolution);

    QPrintDialog *printDialog = new QPrintDialog(&printer, this);
    if (printDialog->exec() == QDialog::Accepted)

    QPainter painter(&printer);
      qDebug() << "-on_pbTest: scene  w=" &lt;&lt; scene-&gt;sceneRect().width() &lt;&lt; " h=" &lt;&lt; scene-&gt;sceneRect().height();
      qDebug() &lt;&lt; "-on_pbTest: printer " << printer.paperRect();
      qDebug() << "-on_pbTest: printer " << printer.resolution();




    debug output is..

    -on_pbTest: scene w= 5100 h= 6600
    -on_pbTest: printer QRect(0,0 5100x6600)
    -on_pbTest: printer 600

Log in to reply