PDA

View Full Version : menubar Hide/remove



vinithr
28th June 2012, 14:38
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

high_flyer
28th June 2012, 14:40
show your code

vinithr
28th June 2012, 16:47
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

high_flyer
29th June 2012, 11:19
You menu bar is empty.
Add a menu item, and it will be visible.

vinithr
3rd July 2012, 11:31
Thanks.

I need to hide the menubar...

Regards
Vinithr

high_flyer
3rd July 2012, 11:52
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?


class Ui_MainWindow
{
public:
QWidget *centralwidget;
QStatusBar *statusbar;
QToolBar *toolBar;

void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(800, 600);
centralwidget = new QWidget(MainWindow);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
MainWindow->setCentralWidget(centralwidget);
statusbar = new QStatusBar(MainWindow);
statusbar->setObjectName(QString::fromUtf8("statusbar"));
MainWindow->setStatusBar(statusbar);
toolBar = new QToolBar(MainWindow);
toolBar->setObjectName(QString::fromUtf8("toolBar"));
MainWindow->addToolBar(Qt::TopToolBarArea, toolBar);

retranslateUi(MainWindow);

QMetaObject::connectSlotsByName(MainWindow);
} // setupUi

void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
toolBar->setWindowTitle(QApplication::translate("MainWindow", "toolBar", 0, QApplication::UnicodeUTF8));
} // retranslateUi

};

mstegehu
31st July 2012, 14:17
In the end this is very poor documented and very easy to accomplish:

Create menu:


// Add help menu
m_helpMenu = m_mainWindow->menuBar ()->addMenu (Tr ("&Help"));

m_helpMenu->setObjectName ("HelpMenu");
m_helpMenu->setWindowTitle (Tr ("Help Menu"));

m_helpMenu->addAction (m_userManualAction);
m_helpMenu->addAction (m_quickStartManualAction);
m_helpMenu->addAction (m_aboutBoxAction);



Remove menu without destroy:


m_mainWindow->menuBar ()->removeAction (m_helpMenu->menuAction ());