Currently, I am trying to pass system X11 events (on Linux) to an object I have created. To do this, I have installed an eventFilter onto my object from my QApplication. This works, in that it gets all of the events of the application. However I need to pass the object X11 events as well.
I went ahead and created a x11Event in my object, hoping that it would receive events from X11, but this does not appear to be the case.
Is there anyway to pass X11 events directly to my object, inside of my application?
You can receive
XEvent
s through:QAbstractEventDispatcher::instance()->setEventFilter()
which will receive allXEvent
s.qApp->setEventFilter()
which will only receive events targeted at the application.QApplication::x11EventFilter
QWidget::x11Event
for your top level window(s) (child widgets don't receiveXEvent
s).in that order. If any of these functions returns
true
for any event, the next function won't receive that event.Some events can also be filtered by Qt between these functions, for example
QWidget::x11Event
doesn't receiveXKeyEvent
s (which are filtered by theQInputContext::x11FilterEvent
function of the widget which has keyboard focus).For more details, you should look at Qt sources: QEventDispatcher_x11.cpp and the function
QApplication::x11ProcessEvent
in QApplication_x11.cppSo for the most part, if you reimplement only the
x11Event
function in yourQDialog
derived class, you should already receive mostXEvent
. And if you want your child widgets to receive them too, you could call manually theirx11Event
functions from your reimplementation ofQDialog::x11Event
.I don't have my dev machine right now so forgive my syntax. I would do the following:
Declare XEvent* as a metatype:
int main() { qRegisterMetatype<XEvent*>(); }
Reimplement
QApplication::x11EventFilter
as alexisdm suggestedCreate a signal in your QApplication reimplementation for example:
void dialogEvent(XEvent*);
Than from anywhere in your application you can do the following:
QApplication *inst = QApllication::instance();
MyApplication *myApp = qobject_cast<MyApplication*>(inst);
if(myApp != 0) {
}
This way you can access x11 event globally. As an alternative you can always reimplement:
for individual widgets