PDA

View Full Version : What will happend if more than one QGraphicsView and QGraphicsScene are used?



nifei
5th March 2009, 06:54
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:


QTabWidget *tabWidget = new QTabWidget();

// tab_0 initialization and add tab_0 to tabWidget
// QPrintPreviewWidget has a QGraphicsView and a QGraphicsScene
// the 1st QGraphicsView and QGraphicsScene
QWidget *tab_0 = new QWidget();
QPrintPreviewWidget *printer_0 = new QPrintPreviewWidget(tab_0);
tab_0->addTab(tab_0, "tab 0");

// tab_1 initialization and add tab_1 to tabWidget
// the 2nd QGraphicsView and QGraphicsScene
QWidget *tab_1 = new QWidget();
QPrintPreviewWidget *printer_1 = new QPrintPreviewWidget(tab_10);
tab_0->addTab(tab_1, "tab 1");

// connections to slot that renders contents on printer
connect( printer_0, SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*)));
connect( printer_1, SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*)));

// the 3rd QGraphicsView and QGraphicsScene
QGraphicsScene scene;
QGraphicsView view(scene);
scene->addWidget(tabWidget);
view.show();