Fredrick Gauss
Fredrick Gauss

Reputation: 5166

Menu Bar not Maximized When Main Window Maximized

In Qt 5.5.1 (Linux), I am showing main window in maximized state as:

QApplication a(argc, argv);
MainWindow w;
w.setWindowState(Qt::WindowMaximized);
w.show();
return a.exec();

In the main window constructor, I call CreateMenuBar which simply creates some menu:

fileMenu = menuBar()->addMenu(tr("&File"));
projectMenu = menuBar()->addMenu(tr("&Project"));
...

When run, Main Window is shown at maximized state correctly but menu bar shortened as:

enter image description here

One strange behaviour is that if I normalized the window with clicking normalize button in window top then maximizing again does stretch the menu bar as it should be.

What am I missing?

Upvotes: 1

Views: 286

Answers (1)

vahancho
vahancho

Reputation: 21258

You can try to call QMainWindow::show() function before setting its state, i.e.:

[..]
w.show();
w.setWindowState(Qt::WindowMaximized);

I am not sure I know the exact reason of such behavior, but I guess that Qt performs incorrect layouting if you try to change its geometry without showing it. It may also depend on window manager you use.

Upvotes: 1

Related Questions