Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMdiSubWindow: is it possible to add menu strip?
Forum Updated to NodeBB v4.3 + New Features

QMdiSubWindow: is it possible to add menu strip?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zulu
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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

      1 Reply Last reply
      2
      • Z Offline
        Z Offline
        zulu
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved