QGraphicsScene has a rendering API that you can use to render a specific part of QGraphicsScene. You can display it on top of QWidget.
void QGraphicsScene :: render (QPainter * artist, const QRectF and target = QRectF (), const QRectF and source = QRectF (), Qt :: AspectRatioMode aspectRatioMode = Qt :: KeepAspectRatio)
something like the following, i tested the following code is working fine.
#include "mygraphicsview.h" #include <QGraphicsScene> #include <QPixmap> #include <QGraphicsView> #include <QPen> #include <QBrush> MyGraphicsView::MyGraphicsView(QWidget *parent) : QWidget(parent) { setGeometry(QRect(100,100,300,300)); scene = new QGraphicsScene(QRect(0,0,600,600)); scene->addRect(20,20,100,100,QPen(),QBrush(Qt::black)); scene->addRect(10,150,100,100,QPen(),QBrush(Qt::red)); } void MyGraphicsView::paintEvent(QPaintEvent *event) { QPainter painter(this); scene->render(&painter,QRect(0,0,300,300),QRect(10,10,200,200)); } #ifndef MYGRAPHICSVIEW_H #define MYGRAPHICSVIEW_H #include <QWidget> class QGraphicsScene; class MyGraphicsView : public QWidget { Q_OBJECT public: MyGraphicsView(QWidget *parent = 0); void paintEvent(QPaintEvent *event); signals: public slots: private: QGraphicsScene* scene; }; #endif // MYGRAPHICSVIEW_H
Kunal source share