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. Adding Menu Bar with no result..
QtWS25 Last Chance

Adding Menu Bar with no result..

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 393 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.
  • 1 Offline
    1 Offline
    1XU7
    wrote on last edited by
    #1

    Hello!!

    I have created a QMainWindow based form (that does not have .ui) and configured it for having MenuBar available and activated.. but there is no menu bar visible in my application.. do i'm missing something? Thanks..

    QtMainWindowMenuBar.png

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #7

      Works fine for me:

      #include <QtWidgets>
      
      int main(int argc, char *argv[])
      {
          QApplication::setAttribute(Qt::AA_DontUseNativeDialogs);
          QMainWindow mainWin;
          mainWin.menuBar()->addMenu(new QMenu("Preferences"));
          mainWin.show();
          return app.exec();
      }
      

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by Christian Ehrlicher
        #2

        Please do not post images but actual text - it's unreadable.
        What I can see is that you create a second QMenuBar for unknown reasons. Use the one from QMainWindow or properly set the QMenuBar to the QMainWindow.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        3
        • 1 Offline
          1 Offline
          1XU7
          wrote on last edited by
          #3

          Right, thanks... im sorry.. just put an image to illustrate result app window and code...

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Anonymous_Banned275
            wrote on last edited by
            #4

            The image posted is perfectly readable and sufficient to illustrate the problem. Why do you question OP reason for adding the second menubar ? His reasoning is immaterial to help resolve the issue. Perhaps edit your post to concentrate / expand on your valid , axtual solutions . ( I wrote this while the OP replied ).

            Christian EhrlicherC 1 Reply Last reply
            1
            • A Anonymous_Banned275

              The image posted is perfectly readable and sufficient to illustrate the problem. Why do you question OP reason for adding the second menubar ? His reasoning is immaterial to help resolve the issue. Perhaps edit your post to concentrate / expand on your valid , axtual solutions . ( I wrote this while the OP replied ).

              Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #5

              @AnneRanch said in Adding Menu Bar with no result..:

              Why do you question OP reason for adding the second menubar

              Because he does and I also properly explained what's wrong - sorry if it's to complicated for you to understand.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              1
              • 1 Offline
                1 Offline
                1XU7
                wrote on last edited by
                #6

                Thanks for answering..

                I have tryied using the default menuBar(),

                Header:

                #ifndef WPRINCIPAL_H
                #define WPRINCIPAL_H
                
                #include <QMainWindow>
                class QMenu;
                class QAction;
                
                class wprincipal : public QMainWindow{
                	Q_OBJECT
                
                private:
                   	QMenu* menu0 {nullptr};       //File...
                   	QAction* act00 {nullptr};     //File -> Preferences...
                
                protected slots:
                   	void ontrigger_act00();
                
                public:
                   	explicit wprincipal(QWidget* _p = nullptr);
                   	~wprincipal(){}
                };
                
                #endif // WPRINCIPAL_H
                

                Source:

                #include "wprincipal.h"
                #include <QMenuBar>
                #include <QMenu>
                
                wprincipal::wprincipal(QWidget* _p) : QMainWindow(_p){
                	act00 = new QAction;
                	act00->setText("Preferences");
                	menu0 = new QMenu;
                	menuBar()->addMenu(menu0);
                	menu0->addAction(act00);
                
                }
                
                void wprincipal::ontrigger_act00(){
                
                }
                

                ...but still something happens that is not being shown:

                bd02918d-8373-4ca8-9eef-00f0a76fe16c-image.png

                1 Reply Last reply
                0
                • Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  Works fine for me:

                  #include <QtWidgets>
                  
                  int main(int argc, char *argv[])
                  {
                      QApplication::setAttribute(Qt::AA_DontUseNativeDialogs);
                      QMainWindow mainWin;
                      mainWin.menuBar()->addMenu(new QMenu("Preferences"));
                      mainWin.show();
                      return app.exec();
                  }
                  

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  0
                  • 1 Offline
                    1 Offline
                    1XU7
                    wrote on last edited by
                    #8

                    Oops, thats weird... i see no big difference between both codes...
                    i will isolate the problem in a new project..
                    thanks.

                    1 Reply Last reply
                    0
                    • Christian EhrlicherC Online
                      Christian EhrlicherC Online
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #9

                      @1XU7 : I also don't see a big difference so can't tell what's wrong.

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      1 Reply Last reply
                      1
                      • 1 Offline
                        1 Offline
                        1XU7
                        wrote on last edited by
                        #10

                        Missed the Title (you wrote it in constructor)

                        menu0 = new QMenu("File");
                        
                        //or
                        
                        menu0 = new QMenu;
                        menu0->setTitle("File");
                        

                        If i miss the title, then bar is not being shown..

                        Thanks.

                        1 Reply Last reply
                        4
                        • 1 1XU7 has marked this topic as solved on

                        • Login

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