Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QMdiSubWindow: is it possible to add menu strip?



  • Hi ALL,
    I have created a MDI interface with several sub windows (QMdiSubWindow).
    I want to add menu bar at the top but form editor does not allow me to do that.
    It is probably because QMdiSubWindow window is inherited from QWidget?
    Cant i implement that?


  • Lifetime Qt Champion

    Hi
    menu strip is menu bar ? like MainWindow has ?
    While you cannot do it in Design mode, it is possible to insert such menu
    via code. However, you need to add a layout also to keep it at top .

    like

    void MainWindow::on_pushButton_released()
    {
        // create new window
        QMdiSubWindow *subWindow1 = new QMdiSubWindow(ui->mdiArea);
        subWindow1->resize(300, 100);
        // create new widget for the mdi window ( the inner ) 
        QWidget *myWidget = new QWidget(subWindow1);
        myWidget->show();
        // make layout and a menu bar
        QVBoxLayout *boxLayout = new QVBoxLayout(myWidget);
        QMenuBar *menuBar = new QMenuBar();
        QMenu *fileMenu = new QMenu("File");
        menuBar->addMenu(fileMenu);
        fileMenu->addAction("Save");
        fileMenu->addAction("Exit");
        // assign menubar to widget
        boxLayout->setMenuBar(menuBar);
    
        // set widget to the MDI window
        subWindow1->setWidget(myWidget);
        subWindow1->show();
    }
    

    alt text



  • Thanks a lot
    that is exactly what i needed
    It seems editor only allow to set menu bar to QMainWindow class :(


Log in to reply