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. Keyboard event not functioning until first mouse click
QtWS25 Last Chance

Keyboard event not functioning until first mouse click

Scheduled Pinned Locked Moved General and Desktop
6 Posts 5 Posters 3.8k 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.
  • L Offline
    L Offline
    lsatenstein
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on last edited by
      #2

      [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.

      http://anavi.org/

      1 Reply Last reply
      0
      • N Offline
        N Offline
        Nosf
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • W Offline
          W Offline
          Wilk
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dbzhang800
            wrote on last edited by
            #5

            I agree with Wilk.

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

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lsatenstein
              wrote on last edited by
              #6

              Will be trying the proposed solutions this morning.

              Thank you for the great suggestions,

              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