Simulate mouseMoveEvent not working QT
-
I am trying to grab touch events from one widget and simulate it in another widget.
The grab and simulate touch events are working fine for mousePressEvent,mouseReleaseEvent.But when I try to
simualate mouseMoveEvent the corresponding events are not getting in the the destination side.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) LiteBlue;}
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;
}The above code is used for grab and simulate. Basically the (QEvent::MouseMove)+ (Qt::LeftButton) is for scrolling a tablewidget.
QCoreApplication::sendEvent returns success.Can any one help me with this. -
Hi and welcome to the forums
I wonder if
https://doc.qt.io/qt-5/qwidget.html#mouseTracking-prop
has any part in this ?since the issues is with mouseMoveEvent and its default off
-
@SmithStanley
so many pitfals with this rather ugly approach to achieve what you want.
the pos is in the source widgets coordinate system.
scrolling is handled by the scrollbar widget (which is a child of the item widget)to sync the scrollbars simply connect the values of them.