Send event to child



  • Hi,

    I need to send a event from a QMainWindow to a other QMainWindow.

    bool MainWindow::event(QEvent *event)
    {
        if (event->type() == QEvent::KeyPress)
        {
            QCoreApplication::sendEvent(w2, new QMouseEvent(QEvent::MouseButtonPress, QPoint(70, 30), Qt::LeftButton, 0, Qt::NoModifier));
        }
        return QMainWindow::event(event);
    }
    

    The event is transfert to the w2 (the second QMainWindow) but not to his children. How a can make this ?

    Best regards,
    Robin



  • Ok I have the soluce :

    QPoint posCursor(pos.x, pos.y);
    QWidget* currentWidget = static_cast<HUD*>(this->scene.GetActor("HUD"))->childAt(posCursor);
    if (currentWidget == nullptr)
    	return true;
    QCoreApplication::sendEvent(currentWidget, new QMouseEvent(QEvent::MouseButtonPress, posCursor - currentWidget->geometry().topLeft(), Qt::MouseButton::LeftButton, 0, Qt::NoModifier));

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.