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. Problems with joystick and mouse events

Problems with joystick and mouse events

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.8k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    Bara86
    wrote on last edited by
    #1

    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)
    return;

    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;
        break;
    case Joystick::BUTTON_5:
        button_pressed = Qt::RightButton;
        break;
    }
    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

    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