int g_cxWorld = 640;int g_cyWorld = 480; class GraphicsView : public QGraphicsView{public: GraphicsView(QGraphicsScene *scene) : QGraphicsView(scene){} virtual void resizeEvent(QResizeEvent *event) { double cx, cy; double khw = double(event->size().height()) / double(event->size().width()); if( khw > (double(g_cyWorld)/double(g_cxWorld)) ) cy = g_cyWorld, cx = (cy/khw); else cx = g_cxWorld, cy = (cx*khw); scene()->items().at(0)->window()->resize(cx,cy); setSceneRect(0,0,cx,cy); fitInView(sceneRect(), Qt::IgnoreAspectRatio); }};int main(int argc, char *argv[]){ QApplication a(argc, argv); MainWindow *pw = new MainWindow; QGraphicsScene scene(0, 0, g_cxWorld, g_cyWorld); pw->resize(g_cxWorld,g_cyWorld); scene.addWidget(pw,Qt::Window); GraphicsView view(&scene); view.show(); return a.exec();}