[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?
-
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. -
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.
-
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.
-
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]
-
This is the gift that keeps on giving. Ran into this problem today and would have never solved it without this thread. Thanks!!!
-
This thread helped me to get to the problem. I would like to propose a quick way to find the solution that worked for me since I had such a big project and many children widgets.
If you know how to subclass an event filter it's pretty simple...
PART 1) in EventFilter.h
#define EVENTFILTER_H #include <QWidget> #include <QDebug> #include <QEvent> class EventFilter : public QWidget { Q_OBJECT public: explicit EventFilter(QWidget *parent = 0); signals: protected: bool eventFilter(QObject *target, QEvent *event); }; #endif // EVENTFILTER_H
PART 2) in EventFilter.cpp
EventFilter::EventFilter(QWidget *parent): QWidget(parent) { } bool EventFilter::eventFilter(QObject *target, QEvent *event) { if (event->type() == QEvent::KeyPress) { QPoint p = QCursor::pos(); QWidget *w = QApplication::widgetAt(p); qDebug() << w; } }
PART 3) in your mainwindow constructor or w/e you load up settings
#include "EventFilter.h" EventFilter* myFilter = new EventFilter(); this->installEventFilter(myFilter);
PART 4) go hunting with your new invisible widget detector!
Just hover your mouse over the defective file menu items and press your spacebar, it should output the topmost offending widget to the console for you to know what you are looking for. In my case it was ANOTHER eventfilter that I had parented mistakenly way back when. Happy hunting!
If you have a small project just use previous methods should be simple enough.