Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.1.0 RC1
-
None
-
qtdeclarative: 536e1cccf15963b586f3112a0654ddc0d101fa69
Description
It is currently impossible to use QObject::eventFilter() to filter events of a QQuickItem. This used to work in Qt 4 with QDeclarativeItem. Run the test case below, hit some keys, and notice that the filter never receives QEvent::KeyPress nor QEvent::KeyRelease.
#include <QtQuick> class Filter : public QObject { bool eventFilter(QObject* object, QEvent* event) { if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease || event->type() == QEvent::ShortcutOverride) { // always a shortcut override (double)...? // QQuickItem(0x13d5810, name = "item") QKeyEvent(ShortcutOverride, 41, 0, ""a"", false, 1) qDebug() << object << static_cast<QKeyEvent*>(event); } return false; } }; int main(int argc, char* argv[]) { QGuiApplication app(argc, argv); Filter filter; QQmlApplicationEngine engine; engine.loadData("import QtQuick 2.1; import QtQuick.Window 2.1; Window { width: 360; height: 360; Item { anchors.fill: parent; objectName: 'item'; focus: true } }"); QWindow* window = qobject_cast<QWindow*>(engine.rootObjects().value(0)); if (window) { window->show(); QObject* item = window->findChild<QObject*>("item"); if (item) item->installEventFilter(&filter); } return app.exec(); }
QQuickItemPrivate::deliverKeyEvent() should use QCoreApplication::sendEvent() or notify() instead of calling the event handlers directly. Using sendEvent() or notify() is not entirely free of problems, though, because then the key event handlers do no longer get called. So perhaps QQuickItem::event() should actually deliver the key event to keyPress/ReleaseEvent().
Attachments
Issue Links
- relates to
-
QTBUG-39837 [Reg 5.2 -> 5.3] Single click produces two events for mouse press and release
- Closed