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 Updated to NodeBB v4.3 + New Features

MainWindow doesnt show MenuBar

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 4 Posters 5.1k 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.
  • V Offline
    V Offline
    Vadik
    wrote on 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

      This post is deleted!

      V Offline
      V Offline
      Vadik
      wrote on 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 last edited by
        #2

        @Vadik said in MainWindow doesnt show MenuBar:

        mb->show();

        vbl->setMenuBar(mb);

        try to remove these lines

        JonBJ V 2 Replies Last reply
        0
        • V Offline
          V Offline
          Vadik
          wrote on last edited by
          #3
          This post is deleted!
          1 Reply Last reply
          0
          • M medyakovvit

            @Vadik said in MainWindow doesnt show MenuBar:

            mb->show();

            vbl->setMenuBar(mb);

            try to remove these lines

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #4

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

            M 1 Reply Last reply
            0
            • M medyakovvit

              @Vadik said in MainWindow doesnt show MenuBar:

              mb->show();

              vbl->setMenuBar(mb);

              try to remove these lines

              V Offline
              V Offline
              Vadik
              wrote on last edited by
              #5

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

              JonBJ 1 Reply Last reply
              0
              • V Vadik

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

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on 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
                0
                • JonBJ JonB

                  @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 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.

                  JonBJ 1 Reply Last reply
                  0
                  • V Vadik

                    @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.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on 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
                    0
                    • JonBJ JonB

                      @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 last edited by
                      #9

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

                      JonBJ 1 Reply Last reply
                      0
                      • V Vadik

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

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on 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
                        0
                        • JonBJ JonB

                          @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 last edited by
                          #11

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

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 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

                            JonBJ V 2 Replies Last reply
                            2
                            • SGaistS SGaist

                              Hi,

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

                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote on 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
                              • SGaistS SGaist

                                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 last edited by
                                #14
                                This post is deleted!
                                V 1 Reply Last reply
                                0
                                • V Vadik

                                  This post is deleted!

                                  V Offline
                                  V Offline
                                  Vadik
                                  wrote on 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
                                  • JonBJ JonB

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

                                    M Offline
                                    M Offline
                                    medyakovvit
                                    wrote on 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.

                                    JonBJ 1 Reply Last reply
                                    1
                                    • M medyakovvit

                                      @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.

                                      JonBJ Offline
                                      JonBJ Offline
                                      JonB
                                      wrote on 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

                                      • Login

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