Solved How to make the title visible for QMainWindow
-
I find that if menu is created on a QMainWindow, then its title text will be covered by the menus.
I create menu bar like this:
QMenuBar *menuBar = new QMenuBar();
this->setMenuBar(menuBar);
menuBar->addMenu("blabla");
...
Then the created window is like this
|x-o menu1 menu2 menu3|
| this is tool bar________|
|__________________|But what I want is like this:
|x-o window title |
|menu1 menu2 menu3 |
|this is tool bar________|
|__________________|How to make the title visible given there are menus?
Thanks in advance! -
Hi @lingan,
which platform are you using? And which Qt version?
-
Hi,
To add to @aha_1980, QMainWindow already provides a menu bar when calling the menuBar function.
-
Hi @lingan,
Now I found what I was searching for.
It's:
menuBar->setNativeMenuBar(false);
Docu: http://doc.qt.io/qt-5/qmenubar.html#nativeMenuBar-prop
-
@aha_1980 Your way works!
Thank you so much!
The platform is Ubuntu 17.04 and QT is of 5.7. Looks the default style of Ubuntu is like this. -
Just be aware that you are "breaking integration" with the desktop environment you use which might not be appreciated by your application users.
You would get the same behaviour on e.g. macOS where the main menu is at the top of the screen and not on your application windows.
-
@SGaist, you are right.
but at least Qt's Ubuntu/Unity integration has some bugs, so that QtCreator uses the non-native menu nowadays.