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?


  • Moderators

    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.



  • Oh yes it solved the problem :)
    But it should not behave like this. :|


  • Moderators

    what do you mean?
    How should it behave?



  • I mean it should appear at right place by default.



  • 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.



  • I have seen a flag in menu tearOffEnabled. if it is not set then menu should appear at right place. I am just expecting that if it is managed for a normal click why not it is for show().


  • Moderators

    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?



  • Just below the menubar and below File title. is not it a default place of a menu?



  • 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.



  • I think in case of context menu we also don't need to care about feed it position. It normally appeared at clicked position default. Yeah in case we want it to appear not on clicked place than we have to care about geometry.


  • Moderators

    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.



  • Thats why I used "default" word. And expecting default behaviour on show().



  • 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.



  • For sake of humanity!
    Joking. I am preparing a demo run of my GUI if user click on Demo the file menu will drop and so so.. I have set state machine to do this in which I am calling fileMenu's show().


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.