QFileMenu not appearing at right place when menuFile->show(); called
-
Hi all,
I am using Qt4.8.3 and in a function I am calling menuFile->show(); to drop the file menu but it is not appearing at right place, it is somewhere near mid of the window. How to drop the filemenu at its right place or it is a bug if with show() it is not appearing at place? -
i guess you mean QMenu right?
Since QMenu inherits QWidget you need to position it first before showing it. Or even better you use QMenu::exec() and pass it the position where to show it.
-
what do you mean?
How should it behave? -
Yes, but what is the default??
Even Menu's may be placed where ever you want, so you need to set the position yourself. The same as adding a widget to a layout.
Your thinking like Win8..............not asking, but just assuming that you want something done automatically......argh...I'm smart, let me decide for myself ;-)
But this is just sidetracking. -
what is the "right place"?
A mouse click and the showing of a menu are not directly related to each other. A menu can also be displayed by keyboard for example, whats the correct place in this case? -
A menu may also be a context menu when click with right mouse button, so, no there is no default place. I think you are right that normally you expect a menu to appear below the label in the menubar and when in Qt Designer you add the menuBar it will be done so. so if you mean that with 'default' position, ok, But menu's may be placed anywhere on screen.
-
but when you use your QMenu as a file menu, meaning you added it to an menu bar of a main window, you don't have to worry about showing and positioning since Qt takes care of it for you.
-
Sure, but why do you use the show() anyway?
That is done in the back by adding your QMenu to the menubar of e.g. a MainWindow. You don't need to call show() on it.
Why don't you try to create a new project with a mainwindow form. Add a menu bar and a menu. Then read the ui_mainwindow.h file and all becomes clear what Qt does for you. There is no need to call show() on the menu. All done by the Menu bar class for you.