... resizeEvent (QResizeEvent* pEvent){ .... setSceneRect (viewport()->rect());}
C++ (Qt)#include <QApplication>#include <QGraphicsScene>#include <QGraphicsView>#include <QGraphicsItem> class CircleItem : public QGraphicsItem{public: CircleItem( qreal radius, QGraphicsItem* parent = 0 ) : QGraphicsItem( parent ) , radius_( radius ) {} virtual ~CircleItem() {} void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0 ) { painter->drawEllipse( QRectF( -radius_ / 2, -radius_ / 2, radius_, radius_ ) ); } QRectF boundingRect() const { return QRectF( -radius_ / 2, -radius_ / 2, radius_, radius_ ); }private: qreal radius_;}; class GraphicsView : public QGraphicsView{public: GraphicsView( QWidget* p = 0 ) : QGraphicsView( p ) {} void resizeEvent( QResizeEvent* e ) { fitInView( scene()->sceneRect() ); }}; int main( int argc, char** argv ){ QApplication app( argc, argv ); GraphicsView gv; QGraphicsScene scene( -150, -150, 300, 300 ); gv.setScene( &scene ); gv.setRenderHint( QPainter::Antialiasing ); for( qreal r = 20; r < 300; r += 10 ) scene.addItem( new CircleItem( r ) ); gv.show(); return app.exec();}