Injecting MouseEvent not working when Window is not focused



  • 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


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Can you explain what you are trying to achieve ?



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


Log in to reply
 

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