Qgraphicsview can't preview by QPrintPreviewDialog



  • @void MainWindow:: openPrintPreviewDialog()
    {
    QPrinter printer(QPrinter::HighResolution);
    printer.setPaperSize(QPrinter::A4);

    QPainter painter(&printer);
    GetCurWindow()->getView()->render(&painter);
    QPrintPreviewDialog preview(&printer,this);
    connect(&preview, SIGNAL(paintRequested(QPrinter *)),this,SLOT(printPreView(QPrinter *)));
    preview.exec();
    }

    void MainWindow:: printPreView( QPrinter * printer)
    {
    ///view
    GraphicsView* currView = GetCurWindow()->getView();
    QPainter painter(printer);
    currView->render(&painter );
    }
    @
    why graphicsview can preview by qprintpreviewdialog ?



  • Please use tag @ for code, just for better readability.



  • Here the code that works for me:
    @

    void MainWindow::print()
    {
    QPrinter printer(QPrinter::HighResolution);
    printer.setPaperSize(QPrinter::A4);
    QPrintPreviewDialog preview(&printer, this);
    connect(&preview, SIGNAL(paintRequested(QPrinter*)), SLOT(printPreview(QPrinter*)));
    preview.exec();
    }

    void MainWindow::printPreview(QPrinter *printer)
    {
    QPainter painter(printer);
    m_graphicsView->render(&painter);
    }
    @


Log in to reply
 

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