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.
目前,我正在尝试将system X11事件(在Linux上)传递给我创建的一个对象。为此,我从q应用程序中安装了一个eventFilter到我的对象上。这是可行的,因为它得到了应用程序的所有事件。不过,我还需要传递对象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事件,希望它能够接收来自X11的事件,但这似乎并不是这样。
Is there anyway to pass X11 events directly to my object, inside of my application?
是否存在直接将X11事件直接传递给我的对象,在我的应用程序内部?
2 个解决方案
#1
3
You can receive XEvent
s through:
您可以通过以下方式接收XEvents:
- a filter function set with
QAbstractEventDispatcher::instance()->setEventFilter()
which will receive allXEvent
s. - 一个带有QAbstractEventDispatcher的过滤器函数::instance()->setEventFilter(),它将接收所有的XEvents。
- a filter function set with
qApp->setEventFilter()
which will only receive events targeted at the application. - 一个带有qApp->setEventFilter()的过滤器函数,它只接收针对应用程序的事件。
- a reimplementation of the virtual function
QApplication::x11EventFilter
- 重新实现虚拟功能QApplication::x11EventFilter。
- a reimplementation of the virtual function
QWidget::x11Event
for your top level window(s) (child widgets don't receiveXEvent
s). - 重新实现虚拟函数QWidget::x11事件为您的顶层窗口(s)(子部件不接收XEvents)。
in that order. If any of these functions returns true
for any event, the next function won't receive that event.
这个顺序。如果其中任何一个函数返回true,那么下一个函数将不会接收该事件。
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在这些函数之间进行过滤,例如,QWidget::x11事件不接收XKeyEvents(这是由QInputContext过滤的::x11FilterEvent函数的小部件有键盘焦点)。
For more details, you should look at Qt sources: QEventDispatcher_x11.cpp and the function QApplication::x11ProcessEvent
in QApplication_x11.cpp
要了解更多细节,您应该查看Qt源:QEventDispatcher_x11。cpp和功能QApplication::x11ProcessEvent在QApplication_x11.cpp中。
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
.
因此,在大多数情况下,如果您在QDialog派生类中重新实现了x11事件函数,那么您应该已经收到了大多数XEvent。如果您希望您的子部件也接收它们,您可以从您的重新实现QDialog::x11事件中手动调用它们的x11事件函数。
#2
1
I don't have my dev machine right now so forgive my syntax. I would do the following:
我现在没有我的开发机器,所以请原谅我的语法。我会这样做:
-
Declare XEvent* as a metatype:
声明XEvent*为元类型:
int main() { qRegisterMetatype<XEvent*>(); }
int main(){ qRegisterMetatype < XEvent * >();}
-
Reimplement
QApplication::x11EventFilter
as alexisdm suggested重新实现QApplication::x11EventFilter,正如alexisdm建议的那样。
-
Create a signal in your QApplication reimplementation for example:
在QApplication重新实现中创建一个信号,例如:
void dialogEvent(XEvent*);
空白dialogEvent(XEvent *);
-
Than from anywhere in your application you can do the following:
在你的应用程序中,你可以做到以下几点:
QApplication *inst = QApllication::instance();
QApplication *本月= QApllication:实例();
MyApplication *myApp = qobject_cast<MyApplication*>(inst);
MyApplication * myApp = qobject_cast < MyApplication * >(本月);
if(myApp != 0) {
如果(myApp ! = 0){
connect(myApp, SIGNAL(dialogEvent(XEvent*), myDialog, SLOT(onXEvent(XEvent*));
}
}
This way you can access x11 event globally. As an alternative you can always reimplement:
这样,您就可以在全球访问x11事件。作为一种选择,你可以随时重新实施:
bool QWidget::x11Event ( XEvent * event )
for individual widgets
单个部件
#1
3
You can receive XEvent
s through:
您可以通过以下方式接收XEvents:
- a filter function set with
QAbstractEventDispatcher::instance()->setEventFilter()
which will receive allXEvent
s. - 一个带有QAbstractEventDispatcher的过滤器函数::instance()->setEventFilter(),它将接收所有的XEvents。
- a filter function set with
qApp->setEventFilter()
which will only receive events targeted at the application. - 一个带有qApp->setEventFilter()的过滤器函数,它只接收针对应用程序的事件。
- a reimplementation of the virtual function
QApplication::x11EventFilter
- 重新实现虚拟功能QApplication::x11EventFilter。
- a reimplementation of the virtual function
QWidget::x11Event
for your top level window(s) (child widgets don't receiveXEvent
s). - 重新实现虚拟函数QWidget::x11事件为您的顶层窗口(s)(子部件不接收XEvents)。
in that order. If any of these functions returns true
for any event, the next function won't receive that event.
这个顺序。如果其中任何一个函数返回true,那么下一个函数将不会接收该事件。
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在这些函数之间进行过滤,例如,QWidget::x11事件不接收XKeyEvents(这是由QInputContext过滤的::x11FilterEvent函数的小部件有键盘焦点)。
For more details, you should look at Qt sources: QEventDispatcher_x11.cpp and the function QApplication::x11ProcessEvent
in QApplication_x11.cpp
要了解更多细节,您应该查看Qt源:QEventDispatcher_x11。cpp和功能QApplication::x11ProcessEvent在QApplication_x11.cpp中。
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
.
因此,在大多数情况下,如果您在QDialog派生类中重新实现了x11事件函数,那么您应该已经收到了大多数XEvent。如果您希望您的子部件也接收它们,您可以从您的重新实现QDialog::x11事件中手动调用它们的x11事件函数。
#2
1
I don't have my dev machine right now so forgive my syntax. I would do the following:
我现在没有我的开发机器,所以请原谅我的语法。我会这样做:
-
Declare XEvent* as a metatype:
声明XEvent*为元类型:
int main() { qRegisterMetatype<XEvent*>(); }
int main(){ qRegisterMetatype < XEvent * >();}
-
Reimplement
QApplication::x11EventFilter
as alexisdm suggested重新实现QApplication::x11EventFilter,正如alexisdm建议的那样。
-
Create a signal in your QApplication reimplementation for example:
在QApplication重新实现中创建一个信号,例如:
void dialogEvent(XEvent*);
空白dialogEvent(XEvent *);
-
Than from anywhere in your application you can do the following:
在你的应用程序中,你可以做到以下几点:
QApplication *inst = QApllication::instance();
QApplication *本月= QApllication:实例();
MyApplication *myApp = qobject_cast<MyApplication*>(inst);
MyApplication * myApp = qobject_cast < MyApplication * >(本月);
if(myApp != 0) {
如果(myApp ! = 0){
connect(myApp, SIGNAL(dialogEvent(XEvent*), myDialog, SLOT(onXEvent(XEvent*));
}
}
This way you can access x11 event globally. As an alternative you can always reimplement:
这样,您就可以在全球访问x11事件。作为一种选择,你可以随时重新实施:
bool QWidget::x11Event ( XEvent * event )
for individual widgets
单个部件