[Solved] First menu on menubar not activating when moused over



  • I have a -QT- Qt designer project with a menu bar containing 3 menus. I cannot select any actions in the first menu until I click the mouse on either the second or third menu. The first menu will then highlight when I mouse over it and the actions are then selectable. There is nothing really unsual in the menu. All of the actions are predefined and no menu dynamics going on. Got any ideas about what's up?



  • It would be helpful if you could provide some code.



  • Here's some of the code generated by the Qt Designer that is in the ui_mainwindow.h file. It shows the definitions of the menu bars, the menus, and the actions. Let me know if there is something else that would prove useful. It is the menuSimulations that appears not to be mouse sensituve.
    @
    menuBar = new QMenuBar(MainWindow);
    menuBar->setObjectName(QString::fromUtf8("menuBar"));
    menuBar->setGeometry(QRect(0, 0, 676, 20));
    menuSimulations = new QMenu(menuBar);
    menuSimulations->setObjectName(QString::fromUtf8("menuSimulations"));
    menu_Recent = new QMenu(menuSimulations);
    menu_Recent->setObjectName(QString::fromUtf8("menu_Recent"));
    menu_Recordings = new QMenu(menuBar);
    menu_Recordings->setObjectName(QString::fromUtf8("menu_Recordings"));
    menuHelp = new QMenu(menuBar);
    menuHelp->setObjectName(QString::fromUtf8("menuHelp"));
    MainWindow->setMenuBar(menuBar);
    statusBar = new QStatusBar(MainWindow);
    statusBar->setObjectName(QString::fromUtf8("statusBar"));
    MainWindow->setStatusBar(statusBar);

        menuBar->addAction(menuSimulations->menuAction());
        menuBar->addAction(menu_Recordings->menuAction());
        menuBar->addAction(menuHelp->menuAction());
        menuSimulations->addAction(actionNew);
        menuSimulations->addAction(actionOpen);
        menuSimulations->addAction(actionSave);
        menuSimulations->addAction(actionS_ave);
        menuSimulations->addAction(menu_Recent->menuAction());
        menuSimulations->addSeparator();
        menuSimulations->addAction(actionPrint);
        menuSimulations->addAction(actionE_xit);
        menu_Recent->addAction(actionFile0);
        menu_Recent->addAction(actionFile1);
        menu_Recent->addAction(actionFile2);
        menu_Recent->addAction(actionFile3);
        menu_Recent->addAction(actionFile4);
        menu_Recent->addAction(actionFile5);
        menu_Recent->addAction(actionFile6);
        menu_Recent->addAction(actionFile7);
        menu_Recent->addAction(actionFile8);
        menu_Recent->addAction(actionFile9);
        menu_Recordings->addAction(action_Open);
        menu_Recordings->addAction(action_Recent);
        menu_Recordings->addAction(action_Print);
        menu_Recordings->addAction(action_Chart);
        menuHelp->addAction(actionAbout_EFTS_Simulator);
    

    @



  • I've seen this once. It turned out a widget was created with the main window as a parent, but incorrectly placed. It could be you are having the same sort of problem. I'd expect that if you open a menu and use the arrow keys to walk through them you can open the menu.

    Something as simple as the following could produce this behavior:
    @MainWindow::MainWindow() :
    QMainWindow()
    {
    //...
    QWidget *w = new Widget(this);
    (void)w;
    }@



  • Yes, I can do that.

    Are you saying that I shoudl look for a widget that has the main window as a parent, but is to properly placed? The things that have MainWindow as the parent are the centralWidget, the menuBar, the statusBar, and all of the menu Actions. There are no other widgets with the mainwindow as the parent.



  • Just for kicks you could see if you can justify all widgets in the tree of children of your main window:

    @QList<QWidget *> children = mainWindow->findChildren<QWidget *>();@

    The description you give sounds very much like an empty widget being placed over your menu.



  • [quote author="Franzk" date="1314044196"]Just for kicks you could see if you can justify all widgets in the tree of children of your main window: @QList<QWidget *> children = mainWindow->findChildren<QWidget *>();@ The description you give sounds very much like an empty widget being placed over your menu.[/quote]
    These are the widgets that I see in the list. The first two are not owns I know of and the last set all have blank names. Is there some way I can look more closely at them?
    a widget called _layout
    a widget called qt_rubberband
    all of the QActions corresponding to my menu actions
    a widget called centralWidget
    a series of widgets with named "".



  • "QObject::dumpObjectInfo()":http://doc.trolltech.com/latest/qobject.html#dumpObjectInfo could help.



  • I've looked through the dump as you have suggested and see nothing that looks unsual as far as I can see. I don't know Qt well enough to be able to explain all of the objects. I can see all that I expect to see, but there are a number that I can't. Here's the ones that I can't explain.
    QRubberBand::qt_rubberband
    QWidget::centralWidget
    OBJECT QWidget::layoutWidget
    QToolButton::qt_menubar_ext_button
    I am using a QTableView and it seems to create a few more scroll bar and header view objects than I would expect.
    I can send the full dump, but that might be a bit much.



  • If possible, could you share the project so we can have a look (zipped, compiling)?



  • I was working on getting you a copy with just the menu problem and not all of the application guts when I found one of my objects that was making the main window a parent. When I removed the relationship the menu starting working. My object was not a widget and does not need the window to own it. Problem solved. Thanx for leading me into the solution.

    I guess I need to read up on parent/child relationships in Qt.



  • Excellent. Happy it works.



  • I was very happy to find this discussion on the menubar issue. I too had the same problem and I was able to track down the QWidget that was causing the problem. However, unlike the above, my widget did need to know its parent. My solution was not not pass in the parent on the constructor, but to create a variable to hold the parent and set it separately. Thanks for your help.



  • bump...for an interesting problem. Had the same issue.

    Side note: it appears to only occur on Windows and not for MacOS code...maybe because the menu is separated from the app window?



  • Bump from me too... two years later! I had the same problem. I was instantiating a child of a KTextEditor with "this" in the constructor. When I changed "this" to 0 the menu now works fine and is clickable and all. Thank you!



  • me 2!

    costs me several weeks of checking...

    until I found this post.

    thx a lot, guys!

    Ruediger



  • Saved my life...ops .. I mean saved lots of my time

    thank you

    [quote author="blane245" date="1314113867"]I was working on getting you a copy with just the menu problem and not all of the application guts when I found one of my objects that was making the main window a parent. When I removed the relationship the menu starting working. My object was not a widget and does not need the window to own it. Problem solved. Thanx for leading me into the solution.

    I guess I need to read up on parent/child relationships in Qt.[/quote]



  • I run into this problem too.
    Change
    label=new QLabel(this)
    to
    label=new QLabel;
    This label has not add too any window, I use it to save QFont.



  • This is the gift that keeps on giving. Ran into this problem today and would have never solved it without this thread. Thanks!!!


Log in to reply
 

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