Printing with QCustomPlot



  • OK, so I thought I'd managed to grasp what to do but sadly it seems not. The following code gives me a preview dialogue (thankfully) but the area where I expect to see the plot is blank (plot is just ui->customplot). Please just point me in the right direction! I need a clue.

    void MainWindow::on_actionPreview_triggered()
    {
        // display print preview dialog
        QPrinter             myprinter( QPrinter::HighResolution );
        QPrintPreviewDialog  mypreview( &myprinter, this );
        connect( &mypreview, SIGNAL(paintRequested(QPrinter*)), SLOT(printfunction(QPrinter*)) );
        mypreview.exec();
    }
    
    void MainWindow::printfunction(QPrinter *aprinter)
    {
        // this is the actual put it on the page bit
        // create a PAINTER do the job
        QCPPainter mypainter(aprinter);
    
        // use the painter to create the page
        int      w = aprinter->pageRect().width();
        int      h = aprinter->pageRect().height();
    //    mypainter.begin(aprinter);
        plot->toPainter(&mypainter, w, h);
        mypainter.end();
    }
    
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.