如何将X11事件传递给QDialog [英] How to pass X11 events to QDialog
问题描述
当前,我正在尝试将系统X11事件(在Linux上)传递给我创建的对象.为此,我已从我的QApplication将eventFilter安装到我的对象上.之所以起作用,是因为它获取了应用程序的所有事件.但是,我还需要传递对象X11事件.
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.
我继续在我的对象中创建了一个x11Event,希望它会接收来自X11的事件,但事实并非如此.
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.
反正有将X11事件直接传递给应用程序内部的对象吗?
Is there anyway to pass X11 events directly to my object, inside of my application?
推荐答案
您可以通过以下方式接收XEvent
:
You can receive XEvent
s through:
- 使用
QAbstractEventDispatcher::instance()->setEventFilter()
设置的过滤器功能,它将接收所有XEvent
. - 使用
qApp->setEventFilter()
设置的过滤器功能,它将仅接收针对该应用程序的事件. - 虚拟功能
QApplication::x11EventFilter
的重新实现
- 为顶层窗口重新实现虚拟功能
QWidget::x11Event
(子小部件不接收XEvent
).
- a filter function set with
QAbstractEventDispatcher::instance()->setEventFilter()
which will receive allXEvent
s. - a filter function set with
qApp->setEventFilter()
which will only receive events targeted at the application. - a reimplementation of the virtual function
QApplication::x11EventFilter
- a reimplementation of the virtual function
QWidget::x11Event
for your top level window(s) (child widgets don't receiveXEvent
s).
按该顺序.如果这些函数中的任何一个对于任何事件都返回true
,则下一个函数将不会接收该事件.
in that order. If any of these functions returns true
for any event, the next function won't receive that event.
在这些功能之间,某些事件也可以由Qt过滤,例如,QWidget::x11Event
不接收XKeyEvent
(由具有键盘焦点的小部件的QInputContext::x11FilterEvent
功能过滤).
Some events can also be filtered by Qt between these functions, for example QWidget::x11Event
doesn't receive XKeyEvent
s (which are filtered by the QInputContext::x11FilterEvent
function of the widget which has keyboard focus).
有关更多详细信息,您应该查看Qt来源: QApplication::x11ProcessEvent
For more details, you should look at Qt sources: QEventDispatcher_x11.cpp and the function QApplication::x11ProcessEvent
in QApplication_x11.cpp
因此,在大多数情况下,如果仅在QDialog
派生类中重新实现x11Event
函数,则应该已经收到大多数XEvent
.而且,如果您希望子小部件也接收它们,则可以在重新实现QDialog::x11Event
时手动调用它们的x11Event
函数.
So for the most part, if you reimplement only the x11Event
function in your QDialog
derived class, you should already receive most XEvent
. And if you want your child widgets to receive them too, you could call manually their x11Event
functions from your reimplementation of QDialog::x11Event
.
这篇关于如何将X11事件传递给QDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!