Menu bar does not show up



  • Hi

    I am following tutorials on youtube. My form has Manu bar and toolbar. I have created one menu named File and under that I have submenu called New Window. I also added actionNew_Window to the toolbar. When I run the program, the toolbar is there but I dont see my menu.

    Any idea?



  • Hi!
    Which tutorial do you use?
    Show us the code.





  • It is very strange if example not works as expected. Did you make any changes in code from example?



  • Nope. I even started the new project and just created one File menu with no submenu. Still does not show up when I run it!!



  • Check if the menu bar is visible with the isVisible() function. You never know



  • There is not visible property for the menu bar or I cannot find it.
    I even add this on main window constructor:
    ui->menuBar->setVisible(true);

    but didnt help



  • There is : ui->menuBar->isVisible()
    Just out of curiosity : what version of Qt are you using?



  • Qt Creator 2.7.0
    Based on Qt 5.0.2 (64 bit)

    Built on Apr 9 2013 at 09:31:19

    isVisible() just checks for visibility but I wanted to set the visibility :)



  • If the following always puts NO in the text filed
    if(ui->menuBar->isVisible())
    ui->plainTextEdit->setPlainText("YES");
    else
    ui->plainTextEdit->setPlainText("No");



  • Can you post your project?



  • mainwindow.h
    @
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include "mydialog.h"
    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

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

    private slots:
    void on_actionNew_Window_triggered();

    private:
    Ui::MainWindow *ui;
    MyDialog *mDialog;
    };

    #endif // MAINWINDOW_H
    @
    @
    mydialog.h

    #ifndef MYDIALOG_H
    #define MYDIALOG_H

    #include <QDialog>

    namespace Ui {
    class MyDialog;
    }

    class MyDialog : public QDialog
    {
    Q_OBJECT

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

    private:
    Ui::MyDialog *ui;
    };

    #endif // MYDIALOG_H
    @
    @
    main.cpp

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

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

    return a.exec();
    }
    @
    @
    mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "mydialog.h"
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {

    ui->setupUi(this);
    //setCentralWidget(ui->plainTextEdit);
    ui->menuBar->setVisible(true);
    if(ui->menuBar->isVisible())
    ui->plainTextEdit->setPlainText("IS");
    else
    ui->plainTextEdit->setPlainText("No");

    }

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

    void MainWindow::on_actionNew_Window_triggered()
    {
    mDialog = new MyDialog(this);
    mDialog->show();
    //mDialog.setModal(true);
    //mDialog.exec();
    }
    @
    @
    mydialog.cpp

    #include "mydialog.h"
    #include "ui_mydialog.h"

    MyDialog::MyDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::MyDialog)
    {
    ui->setupUi(this);
    }

    MyDialog::~MyDialog()
    {
    delete ui;
    }
    @
    @
    mainwindow.h

    Thanks


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.