C++ (Qt)QPixmap pixmap0("maps/Kosovo_map-ru.svg");QGraphicsScene scene;scene.addPixmap(pixmap0);ui->graphicsView->setScene(&scene);
C++ (Qt)void Your_View::resizeEvent(QResizeEvent *event){ QGraphicsView::resizeEvent(event); fitInView(m_your_scene->sceneRect(), Qt::KeepAspectRatio);}
C++ (Qt)class PaintEvent: public QObject { Q_OBJECT public: PaintEvent(QGraphicsView* s):QObject(s),screen(s) {} protected: bool eventFilter(QObject *obj, QEvent *event) { if ( event->type() == QEvent::Resize || event->type() == QEvent::Paint ) { screen->fitInView(screen->rect(), Qt::KeepAspectRatio); return true; } else { return QObject::eventFilter(obj, event); } } private: QGraphicsView* screen;};
C++ (Qt)bool eventFilter(QObject *obj, QEvent *event) { if ( event->type() == QEvent::Resize ) { screen->fitInView(screen->rect(), Qt::KeepAspectRatio); return false; // <----- } else { return QObject::eventFilter(obj, event); } }
C++ (Qt)QGraphicsView* screen;QGraphicsScene scene;......QPixmap pixmap(file_name);QGraphicsPixmapItem item(pixmap);scene.addItem(&item);scene.setSceneRect(0, 0, pixmap.size().width(), pixmap.size().height());screen->fitInView(&item, Qt::KeepAspectRatio);
C++ (Qt)/** в конструкторе */scene = new QGraphicsScene(NULL);ui.graphicsView->setScene(scene);pixmap_item = new QGraphicsPixmapItem();scene->addItem(pixmap_item); /** метод загружающий файл */QPixmap pixmap("file_name.jpg");pixmap_item->setVisible(true);pixmap_item->setPixmap(pixmap);scene->setSceneRect(0, 0, pixmap.width(), pixmap.height());ui.graphicsView->fitInView(pixmap_item, Qt::KeepAspectRatio);