0

I am trying to build an application that after getting some user input on the first window, pops up another window and displays some results. However, even though the menubar is visible on the first window, the menubar does not appear on the second window. The two windows are objects of different classes, but both classes are inherited from QMainWindow.

I have tried using the menuBar() function which returns a pointer for the menubar to add menus (this works for the first window). I also tried creating a new menubar object which didn't help either.

//MapWindow.h

class MapWindow : public QMainWindow
{
    Q_OBJECT
public:
    explicit MapWindow(QWidget *parent = nullptr);
    ~MapWindow();
private:
    QAction *vehicleAct;
    QAction *missionAct;
    QAction *backAct;
    QMenu *toolMenu;
};


//MapWindow.cpp

MapWindow::MapWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MapWindow)
{
    ui->setupUi(this);
    setWindowState(Qt::WindowMaximized);

    vehicleAct = new QAction("Vehicle Selection");
    vehicleAct->setShortcut(Qt::CTRL + Qt::Key_V);

    missionAct = new QAction("Mission Selection");
    missionAct->setShortcut(Qt::CTRL + Qt::Key_M);

    backAct = new QAction("Back");
    backAct->setShortcut(Qt::CTRL + Qt::Key_B);

    toolMenu = menuBar()->addMenu("Tools");
    toolMenu->addAction(vehicleAct);
    toolMenu->addAction(missionAct);
    toolMenu->addAction(backAct);
}

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

When I use the same code in the WelcomeWindow class which is also inherited from QMainWindow it works perfectly. However it doesn't even show a menubar in this second window.

Edin Guso
  • 31
  • 2
  • I suggest, that you post a minimal-reproducible-example, so that you can get some help here. Make it just a new project, so that you can be sure, that it compiles. It is really worth the effort. – Aleph0 Jul 24 '19 at 08:27
  • you have created one QMenu , and it will be displayed in one window, change your code architecture, – Vahagn Avagyan Jul 24 '19 at 08:49
  • @Aleph0 I have tried recreating the problem in a new project, but it works fine and I cannot find a way to recreate the problem. – Edin Guso Jul 24 '19 at 14:47
  • @VahagnAvagyan The above is not the whole code. I thought that posting only the relevant piece of code would make it more readable since this is only a small part of a big project. – Edin Guso Jul 24 '19 at 14:48

1 Answers1

0

I managed to find the problem. One of my widgets (QScrollArea) was located in the top left corner of the screen which was stopping the whole menubar from displaying for some reason. Moving the QScrollArea down a little bit has solved the problem.

Edin Guso
  • 31
  • 2