[Solved] First menu on menubar not activating when moused over
-
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!!!
-
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.
-
@xk hi and welcome to devnet,
Thanks for the mini-guide. You can simplify one thing: EventFilter does not need to inherit QWidget, QObject is fine.
-
-
@blane245 Thanks, lost a lot of time without figuring this out and then I found this useful thread.