[Interest] Problems with joystick and mouse events

Matteo Baracani bara at develer.com
Tue Mar 5 16:57:51 CET 2013


Hi,

first of all I'm sorry for my bad English.
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 som 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);
}


Thanks for your help.

Matteo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130305/83afe002/attachment.html>


More information about the Interest mailing list