Reputation: 5166
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:
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
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