Solved QGraphicsView inside QMainWindow does not work ? (all code snippet pasted)
-
I've no idea why the main window does not display the intended text, yet only blank ?
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { QGraphicsScene scene; scene.addText("Hello, world!"); QGraphicsView *view = new QGraphicsView(this); view->setScene(&scene); this->setCentralWidget(view); }
-
@qt_fan_4k
Hello,
Yourscene
object is on the stack, so it will be destroyed when the constructor exits.Kind regards.
-
Right.
This is not the first time I made such mistake. So the lifecycle of GraphicsScene is required for graphics view.Thanks for the help. This is solved.