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. Injecting MouseEvent not working when Window is not focused

Injecting MouseEvent not working when Window is not focused

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.4k 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.
  • M Offline
    M Offline
    Mokona21
    wrote on last edited by
    #1

    Hi everyone,

    I've got a problem wich I don't know how to handle.
    I'm trying to inject Mouse event this way : @void Mouse::press ( )
    {
    QWidget *receiver = QApplication::widgetAt(m_pos);
    m_button = Qt::LeftButton;
    if (receiver)
    {
    QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonPress, receiver->mapFromGlobal(m_pos), m_button, m_button, Qt::NoModifier);
    QCoreApplication::postEvent(receiver, event);
    }
    }
    @

    This work fine when my app has the focus, but I can't make it work when another window has the focus.
    I've tried this :
    @ // set main window unfocusable
    if (l_app_settings.unfocusable)
    {
    HWND winHandle = (HWND)l_viewer.effectiveWinId();
    ShowWindow(winHandle, SW_HIDE);
    SetWindowLong(winHandle, GWL_EXSTYLE, GetWindowLong(winHandle, GWL_EXSTYLE)
    | WS_EX_NOACTIVATE | WS_EX_APPWINDOW);
    ShowWindow(winHandle, SW_SHOW);
    }
    @

    This work fine with KeyEvent.
    Does anyone have an idea ?

    Thanks a lot for reading me.
    Mokona

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

      Hi and welcome to devnet,

      Can you explain what you are trying to achieve ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • E Offline
        E Offline
        ekoswibowo
        wrote on last edited by
        #3

        Actually, this is much like what I am trying to achieve. Qt should have this thing called QToolWindow. So, we make them float, fill them with controls, but when user interact with the controls, the focus won't shifted from the main application window. Which is just like what tool window should behave.

        I haven' figure out way how to solve this anyway. That WX_EX_NOACTIVATE should've been worked, but I am not sure a proper way to call it. This is my current question in StackOverflow about "this issue":http://stackoverflow.com/questions/24582525/how-to-show-clickable-qframe-without-loosing-focus-from-main-window?noredirect=1#comment38082228_24582525.

        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