Unsolved QWidget objects with Qt::Window flag set do not pass on ignored events
-
Override
QWidget::event
and inspect what the state of the event is after the call to the superclass' method. E.g:#include <qopenglwidget.h> class ChildWindow : public QOpenGLWidget { Q_OBJECT public: // ... bool event(QEvent * e) override { bool result = QOpenGLWidget::event(e); qDebug() << result << e->isAccepted(); return result; } };
Then report your findings here. In principle
QWidget::event
should propagate the event up the object tree. While I don't believe this should be dependent on the window flags, I'm not sure.Kind regards.
-
@kshegunov As far as I can tell the docs mention nothing about this. On the other hand google finds a handful of people stuggling with this dating back half a decade or so. Maybe it's time to read some code :-|
-
@kshegunov And yes, the base class implementation returns true although the event hasn't been accepted. So, to me, still looks as this happens on purpose.
-
-
@Wieland said in QWidget objects with Qt::Window flag set do not pass on ignored events:
As far as I can tell the docs mention nothing about this.
-
@kshegunov I meant it doesn't say anything about event propagation stopping on window boundaries.
-
@Wieland said in QWidget objects with Qt::Window flag set do not pass on ignored events:
I see. Have you confirmed this is because of the flag? I'm not as convinced. I didn't see anything in the code to hint that the flags have any reflection on events propagation. I'd expect the same behavior (key presses not bubbling up) for any window flag that may be passed. -
@kshegunov Flags have some effect, e.g. the popup flag makes the window close on key pressed and then the event is accepted; but otherwise: no. The keyPressEvent() function doesn't do anything but ignore the event and then in the end event() returns true. Maybe there's more magic in the event dispatcher, but the code is quite hard to read.
Edit: Key event propagation actually does work as expected with flag Qt:Widget on the child and when the event is being ignored. But I can't tell where the magic happens :-/
-
Sorry, I give up. :-/
-
Thanks anyway.
BTW, @kshegunov , I did experiment with overriding the Qt::event(...) method, and MainWindow was still getting nothing as long as the child widget was a window. Then I made the child not spawn as a window (instead as a sub-widget) and the ignored event was passed on just fine. For the time being, I'll just click on MainWindow and hit Esc. to close down the program. I don't want to deal with connecting everyone to the MainWindow via signal and slot just to tell it to close.
-
@amdreallyfast said in QWidget objects with Qt::Window flag set do not pass on ignored events:
I did experiment with overriding the Qt::event(...) method, and MainWindow was still getting nothing as long as the child widget was a window. Then I made the child not spawn as a window (instead as a sub-widget) and the ignored event was passed on just fine.
My best advice is to ask in the mailing list if this is intentional, and if it's not to file a bug report.
-
By "mailing list" do you mean the "interest" mailing list? I've already asked one question there and gotten no replies. It is quite busy with "how do I do this?" messages instead of unexpected behavior, so I don't know if I'm asking the right group.