PDA

View Full Version : qgraphicsview can't preview by QPrintPreviewDialog



qylibohao
1st November 2011, 01:54
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 ?

raven-worx
4th November 2011, 08:46
instead of rendering the QGraphicsView, try rendering its viewport, since the viewport contains the content you're interested in.