How to pass X11 events to QDialog
Currently I’m trying to pass system X11 events (on Linux) to an object I created. To do this, I install an eventFilter from my QApplication onto my object. This is valid because it gets all the events of the application. But I also need to pass object X11 events.
I went ahead and created an x11Event in my object in the hope that it would receive events from X11, but that wasn’t.
Is there a way to pass X11 events directly to my objects inside my application?
Solution
You can receive XEvent
:: in the following ways
- Use the filter function
set by QAbstractEventDispatcher::instance()->setEventFilter()
and it will receive allXEvents
. - Use the filter function
set by qApp->setEventFilter()
and it will only receive events for the application. - Reimplementation of the virtual function
QApplication::x11EventFilter
- Reimplement the virtual function
QWidget::x11Event
for your top-level window (child widgets do not receiveXEvent
).
In this order. If any of these functions return true
for any event, the next function will not receive that event.
Qt can also filter some events between these functions, such as QWidget::x11Event
does not receive XKeyEvent
(a function filtered by QInputContext::x11FilterEvent
widget with keyboard focus).
For more details, you should check out the Qt source code: QEventDispatcher_ x11.cpp and functions QApplication:: x11ProcessEvent
in QApplication_x11.cpp
So in most cases, if you only reimplement the x11Event
function in the QDialog
derived class, you should have received most of the XEvent
. If you want your child parts to receive them as well, you can manually call their x11Event
function from the reimplementation of QDialog::x11Event
.