Search code examples
qtqt4qgraphicsviewqmenubar

How to implement Menu bar inside QGraphicsView?


I have a QGraphicsView which shows images dynamically. I also used fitInView feature to resize the window. Now I need to add the menu bar at the top of the QGraphicsView. How to implement this? Please help. I am new in Qt


Solution

  • As beginner it is probably easiest to place your QGraphicsView into a QVBoxLayout and create a QMenuBar and insert it above your graphics view.

    QMenuBar *bar = new QMenuBar();
    ui->yourVerticalLayout->insertWidget( 0, bar );
    
    QMenu* yourMenu = bar->addMenu("Your Menu title");
    QAction* yourFirstAction = yourMenu->addAction("Your First Action");