QImage ::加载jpg没有绘制到视图/场景?

时间:2013-08-08 17:28:31

标签: c++ qt qimage

图片没有被绘制到屏幕上?

QGraphicsScene *scene = new QGraphicsScene();
scene->setSceneRect(0, 0, 996, 996);
scene->setItemIndexMethod(QGraphicsScene::NoIndex);

QGraphicsView *view = new QGraphicsView();
view->setScene(scene);
view->setRenderHint(QPainter::Antialiasing);
view->setBackgroundBrush(Qt::white);
view->setCacheMode(QGraphicsView::CacheBackground);
view->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
view->setDragMode(QGraphicsView::ScrollHandDrag);
view->setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Colliding Mice"));
view->resize(1000, 1000);
view->show();

QImage img(996, 996, QImage::Format_ARGB32);
img.load("/home/blabla/scene8.jpg", 0);
QPainter painter(&img);
view->render(&painter, view->sceneRect());

1 个答案:

答案 0 :(得分:0)

使用基础:Display QImage with QtGui

QGraphicsScene *scene = new QGraphicsScene();

QPixmap image;
image.load("/home/blabla/scene8.jpg", 0);
scene->addPixmap(image);
scene->setSceneRect(image.rect());

QGraphicsView *view = new QGraphicsView();
view->setScene(scene);
view->setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "My Plot"));
view->resize(1000, 1000);
view->show();