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. mimicikng mouse interaction

mimicikng mouse interaction

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.5k Views 3 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.
  • ManuKM Offline
    ManuKM Offline
    ManuK
    wrote on last edited by
    #1

    Hi,
    I want to control my Qt Application with a Leap Motion Device. The Application GUI is some basic menu with buttons, sliders, checkboxes and comboboxes. So far I use a signal to tell my application when the hand position changes so I can control the cursor with my hand. Now I want to click on widgets in the menu. My current approach is to subclass each widget and invoke a "mouse click" when the cursor hovers the widget for some time. My problem is to invoke the "click" for each widget. For buttons it was pretty easy by using the click() slot. For sliders and comboboxes I fiddled around some time but could not manage to get the "mouse-like" behavior (e.g. dragging the slider with the hand).

    So the question for me is: How can I fake the mouse interaction (moving, clicking, dragging, scrolling, etc.) through code in Qt? I think there must be a more general approach than subclassing each widget.
    What just came to my mind is using QTest for that but it feels a bit hackish to use testing mechanics in application code. Do you have any other ideas?

    Btw I am using Qt 5.6 with mscv2015.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi and welcome
      I agree that
      http://doc.qt.io/qt-5/qtest.html#mouseClick
      might be slight hack-ish. But would be easy :)

      Other option would be to install an event filter on the widgets and record
      all events and values and see if you can play it back using QMouseEvent and friends
      where u set the values manually.

      https://forum.qt.io/topic/23852/simulating-mouse-events-properly-solved

      Dragging a slider cannot be done with just mouse click. there will be mutiple events involved.

      I have never tried this but in theory u can store the needed events and re-create it for same effect.

      I made a info function when checking out drag & drop ,
      it might be usefull for u to get names on the events to see what is being sent.
      https://www.dropbox.com/s/9q4laxpv0lm3pcw/eventinfo.txt?dl=0

      I call it like
      qDebug() << "EVENT: " << event->type() << " = " << EventDesc(event->type() );

      1 Reply Last reply
      0
      • Chris KawaC Online
        Chris KawaC Online
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        I don't think you should mess with any widgets.
        It seems to be a matter of faking mouse events. You can find a widget under cursor using widgetAt(). If it returns a widget you just create a fake QMouseEvent and call sendEvent. The widget won't even know if the event came from your device or a real mouse, so no modification to it are needed.

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved