进行搜索这是我找到并放置在“main.cpp”中的内容:
QGraphicsScene scene;
QGraphicsView view(&scene);
但我需要类似以下内容并放置在 "mainwindow.cpp" 中:
QGraphicsScene scene;
QGraphicsView *view = new QGraphicsView();
view->addScene(&scene); //need something like this
这主要工作并显示“黄色”背景。但是,当我在 mainwindow.cpp 中使用 setScene 进行更改时,不会出现黄色背景。
主文件
QGraphicsScene scene;
QGraphicsView view(&scene);
view.setRenderHint(QPainter::Antialiasing);
view.setBackgroundBrush(Qt::yellow);
view.setCacheMode(QGraphicsView::CacheBackground);
view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
view.setDragMode(QGraphicsView::ScrollHandDrag);
view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Colliding Mice"));
view.resize(1000, 800);
view.show();
mainwindow.cpp : 没有黄色背景
QGraphicsScene scene;
QGraphicsView *view = new QGraphicsView();
view->setScene(&scene);
view->setRenderHint(QPainter::Antialiasing);
view->setBackgroundBrush(Qt::yellow);
view->setCacheMode(QGraphicsView::CacheBackground);
view->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
view->setDragMode(QGraphicsView::ScrollHandDrag);
view->setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Colliding Mice"));
view->resize(1000, 800);
view->show();