Results 1 to 7 of 7

Thread: menubar Hide/remove

  1. #1
    Join Date
    Apr 2012
    Posts
    49
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default menubar Hide/remove

    Hi,

    I am trying to remove menubar from form .In form i can able to remove it by right click the form. But when i am running the application its again appears.

    I tried the option like SetEnabled,setdisabled,hide,setvisible .

    The above options does not help me.

    Removing of close,minimize,maximize buttons are also ok for me

    Could you please tell me is there any way to do so.


    Thanks in advance.
    Vinithr

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: menubar Hide/remove

    show your code
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Apr 2012
    Posts
    49
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: menubar Hide/remove

    Thanks for your reply. here i have added a sample test program

    mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    private:
    Ui::MainWindow *ui;
    };

    #endif // MAINWINDOW_H



    mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    // ui->menuBar->hide();
    ui->menuBar->setEnabled(0);
    // ui->menuBar->setDisabled(1);
    // ui->menuBar->setVisible(0);


    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }


    main.cpp


    #include <QtGui/QApplication>
    #include "mainwindow.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
    }



    mainwindow.ui


    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>MainWindow</class>
    <widget class="QMainWindow" name="MainWindow">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>300</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>MainWindow</string>
    </property>
    <widget class="QWidget" name="centralWidget">
    <widget class="QPushButton" name="pushButton">
    <property name="geometry">
    <rect>
    <x>110</x>
    <y>120</y>
    <width>98</width>
    <height>27</height>
    </rect>
    </property>
    <property name="text">
    <string>PushButton</string>
    </property>
    </widget>
    </widget>
    <widget class="QMenuBar" name="menuBar">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>25</height>
    </rect>
    </property>
    </widget>
    <widget class="QToolBar" name="mainToolBar">
    <attribute name="toolBarArea">
    <enum>TopToolBarArea</enum>
    </attribute>
    <attribute name="toolBarBreak">
    <bool>false</bool>
    </attribute>
    </widget>
    <widget class="QStatusBar" name="statusBar"/>
    </widget>
    <layoutdefault spacing="6" margin="11"/>
    <resources/>
    <connections/>
    </ui>


    Thanks vinithr

    Thanks for your reply. here i have added a sample test program

    mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    private:
    Ui::MainWindow *ui;
    };

    #endif // MAINWINDOW_H



    mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    // ui->menuBar->hide();
    ui->menuBar->setEnabled(0);
    // ui->menuBar->setDisabled(1);
    // ui->menuBar->setVisible(0);


    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }


    main.cpp


    #include <QtGui/QApplication>
    #include "mainwindow.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
    }



    mainwindow.ui


    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>MainWindow</class>
    <widget class="QMainWindow" name="MainWindow">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>300</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>MainWindow</string>
    </property>
    <widget class="QWidget" name="centralWidget">
    <widget class="QPushButton" name="pushButton">
    <property name="geometry">
    <rect>
    <x>110</x>
    <y>120</y>
    <width>98</width>
    <height>27</height>
    </rect>
    </property>
    <property name="text">
    <string>PushButton</string>
    </property>
    </widget>
    </widget>
    <widget class="QMenuBar" name="menuBar">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>25</height>
    </rect>
    </property>
    </widget>
    <widget class="QToolBar" name="mainToolBar">
    <attribute name="toolBarArea">
    <enum>TopToolBarArea</enum>
    </attribute>
    <attribute name="toolBarBreak">
    <bool>false</bool>
    </attribute>
    </widget>
    <widget class="QStatusBar" name="statusBar"/>
    </widget>
    <layoutdefault spacing="6" margin="11"/>
    <resources/>
    <connections/>
    </ui>


    Thanks vinithr

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: menubar Hide/remove

    You menu bar is empty.
    Add a menu item, and it will be visible.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Apr 2012
    Posts
    49
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: menubar Hide/remove

    Thanks.

    I need to hide the menubar...

    Regards
    Vinithr

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: menubar Hide/remove

    I can't reproduce your problem.
    I don't see any menu bar if I remove the menu bar in designer it doesn't get showed in my window.
    Here is the generate ui_*.h file as you can see no menu bar is added.
    So probably there is not correlation between what you think you do, and what you really do.
    Did you remember to save your ui changes?
    Qt Code:
    1. class Ui_MainWindow
    2. {
    3. public:
    4. QWidget *centralwidget;
    5. QStatusBar *statusbar;
    6. QToolBar *toolBar;
    7.  
    8. void setupUi(QMainWindow *MainWindow)
    9. {
    10. if (MainWindow->objectName().isEmpty())
    11. MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
    12. MainWindow->resize(800, 600);
    13. centralwidget = new QWidget(MainWindow);
    14. centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
    15. MainWindow->setCentralWidget(centralwidget);
    16. statusbar = new QStatusBar(MainWindow);
    17. statusbar->setObjectName(QString::fromUtf8("statusbar"));
    18. MainWindow->setStatusBar(statusbar);
    19. toolBar = new QToolBar(MainWindow);
    20. toolBar->setObjectName(QString::fromUtf8("toolBar"));
    21. MainWindow->addToolBar(Qt::TopToolBarArea, toolBar);
    22.  
    23. retranslateUi(MainWindow);
    24.  
    25. QMetaObject::connectSlotsByName(MainWindow);
    26. } // setupUi
    27.  
    28. void retranslateUi(QMainWindow *MainWindow)
    29. {
    30. MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
    31. toolBar->setWindowTitle(QApplication::translate("MainWindow", "toolBar", 0, QApplication::UnicodeUTF8));
    32. } // retranslateUi
    33.  
    34. };
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Sep 2008
    Posts
    54
    Thanks
    3
    Thanked 10 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default Re: menubar Hide/remove

    In the end this is very poor documented and very easy to accomplish:

    Create menu:
    Qt Code:
    1. // Add help menu
    2. m_helpMenu = m_mainWindow->menuBar ()->addMenu (Tr ("&Help"));
    3.  
    4. m_helpMenu->setObjectName ("HelpMenu");
    5. m_helpMenu->setWindowTitle (Tr ("Help Menu"));
    6.  
    7. m_helpMenu->addAction (m_userManualAction);
    8. m_helpMenu->addAction (m_quickStartManualAction);
    9. m_helpMenu->addAction (m_aboutBoxAction);
    To copy to clipboard, switch view to plain text mode 


    Remove menu without destroy:
    Qt Code:
    1. m_mainWindow->menuBar ()->removeAction (m_helpMenu->menuAction ());
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Remove or hide title bar
    By tlerner in forum Qt Programming
    Replies: 3
    Last Post: 1st July 2013, 04:41
  2. Replies: 3
    Last Post: 4th May 2011, 14:29
  3. [QT] MenuBar
    By iVo1d in forum Qt Programming
    Replies: 2
    Last Post: 18th August 2010, 13:14
  4. How to hide/remove a addMenu() menu
    By MrGarbage in forum Qt Programming
    Replies: 2
    Last Post: 3rd August 2007, 23:32
  5. Using the menubar
    By Steve in forum Newbie
    Replies: 10
    Last Post: 27th February 2006, 15:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.