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. MainWindow doesnt show MenuBar
Forum Update on Monday, May 27th 2025

MainWindow doesnt show MenuBar

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 4 Posters 5.0k Views
  • 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.
  • V Offline
    V Offline
    Vadik
    wrote on 19 Nov 2017, 18:15 last edited by Vadik
    #1

    Created project with MainWindow shows only included Widget, but no MenuBar. Cant understand why, help me please.

    Important Note: the same code works correctly on other machines, only on my computer it show wrong result.

    The image demonstrate what i got instead of menu bar.
    0_1511119744652_problem.png

    QMake version 3.0
    Using Qt version 5.5.1
    Ubuntu 16.04

    Below mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QtGui>
    #include <QWidget>
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        MainWindow(QWidget *parent = 0);
        ~MainWindow();
    private:
        QMenu *file;
    };
    
    #endif // MAINWINDOW_H
    

    Below mainwindow.cpp

    #include "mainwindow.h"
    #include <QtGui>
    #include <QtWidgets>
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
    {
        //QVBoxLayout *vbl = new QVBoxLayout;
        QMenu *file = new QMenu("&File"); //menuBar()->addMenu("&File");//new QMenu("&File");
        file->addAction("&Quit",qApp,SLOT(quit()),Qt::CTRL+Qt::Key_Q);
    
    
        QMenuBar *mb = menuBar();
    
        mb->addMenu(file);
        mb->show();
        setMenuBar(mb);
    
        //vbl->setMenuBar(mb);
        //setLayout(vbl);
    
        resize(400,400);
    }
    
    MainWindow::~MainWindow()
    {
    
    }
    
    1 Reply Last reply
    0
    • V Vadik
      19 Nov 2017, 23:43

      This post is deleted!

      V Offline
      V Offline
      Vadik
      wrote on 19 Nov 2017, 23:52 last edited by Vadik
      #15

      @Vadik YEEEEAH, solved, after some investigations and reinstalling of all components it turned out. Need to change in 'System Settings -> Appearance -> Behavior' parameter for 'Show the menus for a window' from the "In the menu bar" to "In the window's title bar". Thanks to everyone who tried to help.

      1 Reply Last reply
      1
      • M Offline
        M Offline
        medyakovvit
        wrote on 19 Nov 2017, 18:33 last edited by
        #2

        @Vadik said in MainWindow doesnt show MenuBar:

        mb->show();

        vbl->setMenuBar(mb);

        try to remove these lines

        J V 2 Replies Last reply 19 Nov 2017, 18:43
        0
        • V Offline
          V Offline
          Vadik
          wrote on 19 Nov 2017, 18:41 last edited by
          #3
          This post is deleted!
          1 Reply Last reply
          0
          • M medyakovvit
            19 Nov 2017, 18:33

            @Vadik said in MainWindow doesnt show MenuBar:

            mb->show();

            vbl->setMenuBar(mb);

            try to remove these lines

            J Offline
            J Offline
            JonB
            wrote on 19 Nov 2017, 18:43 last edited by JonB
            #4

            @medyakovvit
            Won't he need setMenuBar(sb) for his main window too?

            M 1 Reply Last reply 20 Nov 2017, 10:48
            0
            • M medyakovvit
              19 Nov 2017, 18:33

              @Vadik said in MainWindow doesnt show MenuBar:

              mb->show();

              vbl->setMenuBar(mb);

              try to remove these lines

              V Offline
              V Offline
              Vadik
              wrote on 19 Nov 2017, 18:47 last edited by
              #5

              @medyakovvit Already tried this, and many of other combination "removing-adding". No one helps

              J 1 Reply Last reply 19 Nov 2017, 19:05
              0
              • V Vadik
                19 Nov 2017, 18:47

                @medyakovvit Already tried this, and many of other combination "removing-adding". No one helps

                J Offline
                J Offline
                JonB
                wrote on 19 Nov 2017, 19:05 last edited by
                #6

                @Vadik
                So you've tried this?

                QMenuBar *mb = menuBar();
                mb->addMenu(file);
                this->setMenuBar(mb);
                

                Also see https://stackoverflow.com/questions/41367027/qt-add-menubar-menus-and-sub-menus-to-qmainwindow

                V 1 Reply Last reply 19 Nov 2017, 19:14
                0
                • J JonB
                  19 Nov 2017, 19:05

                  @Vadik
                  So you've tried this?

                  QMenuBar *mb = menuBar();
                  mb->addMenu(file);
                  this->setMenuBar(mb);
                  

                  Also see https://stackoverflow.com/questions/41367027/qt-add-menubar-menus-and-sub-menus-to-qmainwindow

                  V Offline
                  V Offline
                  Vadik
                  wrote on 19 Nov 2017, 19:14 last edited by
                  #7

                  @JNBarchan said in MainWindow doesnt show MenuBar:

                  QMenuBar *mb = menuBar();
                  mb->addMenu(file);
                  this->setMenuBar(mb);

                  yes, have tried, and the same code is working on other machines.

                  J 1 Reply Last reply 19 Nov 2017, 19:18
                  0
                  • V Vadik
                    19 Nov 2017, 19:14

                    @JNBarchan said in MainWindow doesnt show MenuBar:

                    QMenuBar *mb = menuBar();
                    mb->addMenu(file);
                    this->setMenuBar(mb);

                    yes, have tried, and the same code is working on other machines.

                    J Offline
                    J Offline
                    JonB
                    wrote on 19 Nov 2017, 19:18 last edited by
                    #8

                    @Vadik
                    Oh, this is the first time you're saying the code works on some machines and not others?

                    V 1 Reply Last reply 19 Nov 2017, 19:33
                    0
                    • J JonB
                      19 Nov 2017, 19:18

                      @Vadik
                      Oh, this is the first time you're saying the code works on some machines and not others?

                      V Offline
                      V Offline
                      Vadik
                      wrote on 19 Nov 2017, 19:33 last edited by
                      #9

                      @JNBarchan yeah, I just forgot, allready corrected. Thanks for reminder.

                      J 1 Reply Last reply 19 Nov 2017, 19:42
                      0
                      • V Vadik
                        19 Nov 2017, 19:33

                        @JNBarchan yeah, I just forgot, allready corrected. Thanks for reminder.

                        J Offline
                        J Offline
                        JonB
                        wrote on 19 Nov 2017, 19:42 last edited by
                        #10

                        @Vadik
                        So I would look at exactly what version of Qt libraries is being used on your machine versus other machines? Maybe they have a later version than your 5.5, and it will work then?

                        V 1 Reply Last reply 19 Nov 2017, 20:48
                        0
                        • J JonB
                          19 Nov 2017, 19:42

                          @Vadik
                          So I would look at exactly what version of Qt libraries is being used on your machine versus other machines? Maybe they have a later version than your 5.5, and it will work then?

                          V Offline
                          V Offline
                          Vadik
                          wrote on 19 Nov 2017, 20:48 last edited by
                          #11

                          @JNBarchan Allready reinstalled Qt up to 5.9.2 version. And still didn't help

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 19 Nov 2017, 20:52 last edited by SGaist
                            #12

                            Hi,

                            Aren't you on Ubuntu ? If so, isn't your menu bar shown at the top of the screen macOS like ?

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            J V 2 Replies Last reply 19 Nov 2017, 20:55
                            2
                            • S SGaist
                              19 Nov 2017, 20:52

                              Hi,

                              Aren't you on Ubuntu ? If so, isn't your menu bar shown at the top of the screen macOS like ?

                              J Offline
                              J Offline
                              JonB
                              wrote on 19 Nov 2017, 20:55 last edited by
                              #13

                              @SGaist
                              LOL if that's what OP means. I have my desktop preference set to show menus on windows, but the default is on system menu.

                              1 Reply Last reply
                              1
                              • S SGaist
                                19 Nov 2017, 20:52

                                Hi,

                                Aren't you on Ubuntu ? If so, isn't your menu bar shown at the top of the screen macOS like ?

                                V Offline
                                V Offline
                                Vadik
                                wrote on 19 Nov 2017, 23:43 last edited by
                                #14
                                This post is deleted!
                                V 1 Reply Last reply 19 Nov 2017, 23:52
                                0
                                • V Vadik
                                  19 Nov 2017, 23:43

                                  This post is deleted!

                                  V Offline
                                  V Offline
                                  Vadik
                                  wrote on 19 Nov 2017, 23:52 last edited by Vadik
                                  #15

                                  @Vadik YEEEEAH, solved, after some investigations and reinstalling of all components it turned out. Need to change in 'System Settings -> Appearance -> Behavior' parameter for 'Show the menus for a window' from the "In the menu bar" to "In the window's title bar". Thanks to everyone who tried to help.

                                  1 Reply Last reply
                                  1
                                  • J JonB
                                    19 Nov 2017, 18:43

                                    @medyakovvit
                                    Won't he need setMenuBar(sb) for his main window too?

                                    M Offline
                                    M Offline
                                    medyakovvit
                                    wrote on 20 Nov 2017, 10:48 last edited by
                                    #16

                                    @JNBarchan Question is solved, but as you asked.
                                    I don't think it's needed as he gets pointer to menu bar with:

                                    QMenuBar *mb = menuBar();
                                    

                                    and this function returns the menu bar that already set.

                                    J 1 Reply Last reply 20 Nov 2017, 10:51
                                    1
                                    • M medyakovvit
                                      20 Nov 2017, 10:48

                                      @JNBarchan Question is solved, but as you asked.
                                      I don't think it's needed as he gets pointer to menu bar with:

                                      QMenuBar *mb = menuBar();
                                      

                                      and this function returns the menu bar that already set.

                                      J Offline
                                      J Offline
                                      JonB
                                      wrote on 20 Nov 2017, 10:51 last edited by JonB
                                      #17

                                      @medyakovvit
                                      Yeah, I kinda mis-read (C++ not being my language) it as having been:

                                      QMenuBar *mb = new QMenuBar();
                                      

                                      thinking he was creating his own new one which would need setting. Using the existing menubar and changing its content is of course preferable.

                                      1 Reply Last reply
                                      0

                                      5/17

                                      19 Nov 2017, 18:47

                                      topic:navigator.unread, 12
                                      • Login

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