Problems with joystick and mouse events

  • Hi,
    in my Qt application I've to substitute the mouse with a joystick. I've implement the cursor's movement and the left/right click. To simulate the mouse click I've connect the joystick buttons press/release signal to a slot that create a QMouseEvent and send it to the widget under the cursor. This work for some widget but not for others; in particular:

    • On QComboBox I can open the dialog and select and item but if I click outside the combobox the dialog stay open.
    • On QSpinBox if the click is on the lineedit to select it I have to use setFocus on it.
    • On QMainWindow the right click doesn't show the popup menu for the dock widget.

    The slot to manage the joystick button press is this:
    @void DisplayWindow::joystickButtonPressed(int button)
    QPoint cursor_position = QCursor::pos();
    QWidget *widget_under_cursor = QApplication::widgetAt(cursor_position);
    if (!widget_under_cursor)

    QPoint coordinate = widget_under_cursor->mapFromGlobal(cursor_position);
    Qt::MouseButton button_pressed;
    switch (static_cast<Joystick::JoystickButton>(button))
    case Joystick::BUTTON_4:
        button_pressed = Qt::LeftButton;
    case Joystick::BUTTON_5:
        button_pressed = Qt::RightButton;
    QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonPress, coordinate,
                                                                                button_pressed, button_pressed, Qt::NoModifier);
    QApplication::postEvent(widget_under_cursor, event);


    The release SLOT is equal to this one, the only difference is that I create a QMouseEvent with type QEvene::MouseButtonRelease

    I'm working on Windows 7 64 bit and I use Qt 4.7.4

    Thanks for your help

Log in to reply

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