我正在尝试从一个小部件中抓取触摸事件并在另一个小部件中对其进行模拟。对于 mousePressEvent、mouseReleaseEvent,抓取和模拟触摸事件工作正常。但是当我尝试模拟 mouseMoveEvent 时,相应的事件没有进入目标端。
void SimulateManager::showWidgets()
{
Source.show();
Destination.show();
connect(&Source, SIGNAL(sigMousePress(QMouseEvent *)), this,
SLOT(slotMousePress(QMouseEvent *)));
connect(&Source, SIGNAL(sigMouseMove(QMouseEvent *)), this,
SLOT(slotMouseMove(QMouseEvent *)));
}
void SourceWidget:: mouseMoveEvent(QMouseEvent *event)
{
emit sigMouseMove(event);
}
void SourceWidget::mousePressEvent(QMouseEvent *event)
{
emit sigMousePress(event);
}
void SimulateManager:: slotMousePress(QMouseEvent *event)
{
QPoint pPoint(event->pos().x(),event->pos().y());
QMouseEvent mouseEvent( (QEvent::MouseButtonPress),pPoint, Qt::LeftButton, Qt::NoButton,Qt::NoModifier );
QCoreApplication::sendEvent(&Destination, &mouseEvent);
}
void SimulateManager:: slotMouseMove(QMouseEvent *event)
{
QPoint pPoint(event->pos().x(),event->pos().y());
QMouseEvent mouseEvent( (QEvent::MouseMove),pPoint, Qt::LeftButton,
Qt::NoButton,Qt::NoModifier );
QCoreApplication::sendEvent(&Destination, &mouseEvent);
}
void DesitinationWidget:: mouseMoveEvent(QMouseEvent *event)
{
qDebug()<<Q_FUNC_INFO;
}
void DesitinationWidget::mousePressEvent(QMouseEvent *event)
{
qDebug()<<Q_FUNC_INFO;
}
以上代码用于抓取和模拟。基本上 (QEvent::MouseMove)+ (Qt::LeftButton) 用于滚动表格小部件。QCoreApplication::sendEvent 返回成功。任何人都可以帮我解决这个问题。