In my project more than one QPrintPreviewWidgets will be put in different tabs of one QTabWidget, and QPrintPreviewWidget has one QGraphicsView and one QGraphicsScene to render the contents. At the same time, the QTabWidget will be put into a QGraphicsScene via QGraphicsProxyWidget. My code is:
Qt Code:
  1. QTabWidget *tabWidget = new QTabWidget();
  2.  
  3. // tab_0 initialization and add tab_0 to tabWidget
  4. // QPrintPreviewWidget has a QGraphicsView and a QGraphicsScene
  5. // the 1st QGraphicsView and QGraphicsScene
  6. QWidget *tab_0 = new QWidget();
  7. QPrintPreviewWidget *printer_0 = new QPrintPreviewWidget(tab_0);
  8. tab_0->addTab(tab_0, "tab 0");
  9.  
  10. // tab_1 initialization and add tab_1 to tabWidget
  11. // the 2nd QGraphicsView and QGraphicsScene
  12. QWidget *tab_1 = new QWidget();
  13. QPrintPreviewWidget *printer_1 = new QPrintPreviewWidget(tab_10);
  14. tab_0->addTab(tab_1, "tab 1");
  15.  
  16. // connections to slot that renders contents on printer
  17. connect( printer_0, SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*)));
  18. connect( printer_1, SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*)));
  19.  
  20. // the 3rd QGraphicsView and QGraphicsScene
  21. QGraphicsView view(scene);
  22. scene->addWidget(tabWidget);
  23. view.show();
To copy to clipboard, switch view to plain text mode