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 Champions 2016

    @qt_fan_4k
    Hello,
    Your scene 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.