我正在注入键盘和鼠标事件,这些事件通过网络传入我的Qt应用程序并QCoreApplication::postEvent用于此.鼠标坐标是绝对屏幕像素坐标.
QMouseEvent *event = new QMouseEvent(type, QPoint(x, y), mouse_button, mouse_buttons,
Qt::NoModifier);
QCoreApplication::postEvent(g_qtdraw.main.widget, event);
Run Code Online (Sandbox Code Playgroud)
最初我只有一个小部件(引用g_qtdraw.main.widget)所以我只是使用那个小部件作为接收器参数postEvent.现在我的应用程序有多个小部件,上面的代码不能再做我想要的了.
第二个小部件以全屏模式显示,我知道所有鼠标事件都必须转到此窗口,但使用上面的代码,它们仍然会路由到主窗口小部件.
如何选择正确的小部件作为接收器(鼠标x,y coords下的小部件)?有没有一种标准的方式,所以Qt选择正确的小部件还是我必须自己跟踪?
编辑
我现在使用以下工作正常(非常感谢Dusty Campbell):
QPoint pos(x, y);
QWidget *receiver = QApplication::widgetAt(pos);
if (receiver) {
QMouseEvent *event = new QMouseEvent(type, receiver->mapFromGlobal(pos), mouse_button,
mouse_buttons, Qt::NoModifier);
QCoreApplication::postEvent(receiver, event);
}
Run Code Online (Sandbox Code Playgroud) 如何使用py2.6,Windows OS找到处理器ID?
我知道有pycpuid,但我无法在2.6下编译.