Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Send event to child
Qt 6.11 is out! See what's new in the release blog

Send event to child

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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));
      
      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved