View Full Version : Custom event gets not propagated to the top level widget

29th January 2009, 09:06
Good morning.

I've written the following custom QEvent:

class LogEvent: public QEvent {
enum LogLevel {
Debug, Info, Warn, Error

LogEvent(QString message, LogLevel level) :
QEvent(LogEvent::custom_type()), _message(message), _level(level) {

static QEvent::Type custom_type() {
static int type = QEvent::registerEventType();
return (QEvent::Type) type;

QString getMessage() {
return _message;

LogLevel getLogLevel() {
return _level;

QString _message;
LogLevel _level;

In my top level widget (inherited from QWindow) I've overwritten the following method:

bool MainWindow::event(QEvent* e) {
if(e->type() == LogEvent::custom_type()) {
qDebug() << "LogEvent received";
return true;
} else {
return QWidget::event(e);

when I send an event with this code:

qApp->postEvent(this, new LogEvent("This is my message", LogEvent::Debug));

from the MainWindow the message gets received (of cause, since this is the instance of MainWindow), but if I send the message from a child of MainWindow I get nothing. It seems, that the custom Event get not propagated to the parent. The docs for QEvent::ignore() say:

Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).

Clearing the accept parameter indicates that the event receiver does not want the event. Unwanted events might be propgated to the parent widget.

I've no custom event handler except for the one in the MainWindow. What gets wrong, that my event is not propagated to the parent? Maybe the Widget, that gets the event first, accepts it, but why? The QEvent::type() should not be known by the default event handler. Any Ideas? I'm using Qt 4.5 beta1 (Linux)