Keyboard event not functioning until first mouse click



  • I am seeking help for what appears to be an event trapping problem.

    An application which consists of a matrix of 3 x 8 cells, has each cell functioning like a button. The target systems for which this application will run has no mouse. However each of our development systems, (Linux) has a mouse.

    When I start the application, it comes up almost correctly. It displays correctly. But all keyboard activity is refused (left, right, up, down, enter, tab, etc. etc.. until I click a mouse button with the mouse pointer anywhere (on or off the mainWindow). The mouse click appears to initialize the event processor (filter), and from thereon, the keyboard and application operate as anticipated.

    Since the target system has no mouse, I would like to know if there is a class or Qt function to simulate a mouse click. This is not the best solution, but is one that will work. Is there a method to initialize the event filter for keyboard detection?

    I've done some searching, but have not discovered a function or class with which I could experiment.

    I have tested with different QtSDK versions using Ubuntu, Fedora, Debian, Centos, (32 and 64 bit systems). Only on one system does the keyboard appear to function on application startup. But... with a recent Qt upgrade, this is no longer the case.

    Any guidance or suggestions about where to look to solve this worrisome probem would be appreciated.



  • [quote author="lsatenstein" date="1334862985"]
    Since the target system has no mouse, I would like to know if there is a class or Qt function to simulate a mouse click. This is not the best solution, but is one that will work. Is there a method to initialize the event filter for keyboard detection? [/quote]

    You can simulate mouse events using class "QTestEventList":http://doc.qt.nokia.com/main-snapshot/qtesteventlist.html Use "addMouseClick":http://doc.qt.nokia.com/main-snapshot/qtesteventlist.html#addMouseClick to simulate a single click.



  • I guess you can simulate the mouse click by

    @
    QApplication::postEvent(main_window, new QMouseEvent(QEvent::MouseButtonPress, QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier));
    @

    I am not sure this is the right approach though. You can try to see if this gets you sorted until you get a better solution to sort the Event propagation.



  • Hello
    Try using "QWidget::setFocus()":http://qt-project.org/doc/qt-4.8/qwidget.html#setFocus-2 slot or "QWidget::setFocus()":http://qt-project.org/doc/qt-4.8/qwidget.html#setFocus method with "Qt::MouseFocusReason or Qt::OtherFocusReason":http://qt-project.org/doc/qt-4.8/qt.html#FocusReason-enum as argument. Also you may try "QWidget::setFocusPolicy()":http://qt-project.org/doc/qt-4.8/qwidget.html#focusPolicy-prop.



  • I agree with Wilk.

    Make sure your window is activated and your widget has focus.



  • Will be trying the proposed solutions this morning.

    Thank you for the great suggestions,


Log in to reply
 

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