2
votes

I have a QWidget which contains some Line Edits. I have to pop up a new Numpad widget when the Line edit gets the the focus. When i click on the Numpad widget, the focus has to be remained in the Line edit widget. So i tried using

bool NumPadWidget::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
    #ifdef Q_OS_WIN
        if(eventType == "windows_generic_MSG")
        {
            const MSG *msg = reinterpret_cast<MSG *>(message);
            if(msg->message == WM_MOUSEACTIVATE)
            {
                *result = MA_NOACTIVATE;
                return true;
            }
        }
    #endif
        return false;
}

This is working fine for Mouse clicks of the numpad widget, but i am using a Touch screen. when i touch the Numpad widget, there is a flickering ( title bar flashing effect) on the LineEdit widget. So can anyone please tell me which Macro i have to use to block the focus of the widget on the touch screen.

I tried using WM_Touch macro which results in no proper output. Please help…

2
I would love to help you out, but I would need a Short, Self Contained, Correct (Compilable), Example.karlphillip

2 Answers

1
votes

Thanks N1ghtLight for your reply. I tried using WM_GESTURE message. It is accepting the touch input but the focus issue (title bar of the LineEdit Widget shows inactive) is still exists. Here's my code.

bool NumPadWidget::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
    #ifdef Q_OS_WIN
        if(eventType == "windows_generic_MSG")
        {
            const MSG *msg = reinterpret_cast<MSG *>(message);
            if(msg->message == WM_MOUSEACTIVATE || msg->message == WM_GESTURE)
            {
                *result = MA_NOACTIVATE;
                return true;
            }
        }
    #endif
        return false;
}

Please suggest me where i am going wrong.

EDIT:

When I try this below code, it solves the issue, But now it is not working for the Mouse Clicks. But, I want the widget to handle both the Touch and the Mouse Clicks. So Can anyone please tell me the macro which is used to handle both the touch and the Mouse clicks.

bool NumPadWidget::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
   #ifdef Q_OS_WIN
     if(eventType == "windows_generic_MSG")
     {
        const MSG *msg = reinterpret_cast<MSG *>(message);
        if(msg->message == WM_MOUSEACTIVATE)
       {
            *result = MA_NOACTIVATEANDEAT;;
             return true;
       }
    }
    #endif
        return false;
}

From the Documentation, MA_ACTIVATE Activates the window, and does not discard the mouse message. MA_ACTIVATEANDEAT Activates the window, and discards the mouse message. MA_NOACTIVATE Does not activate the window, and does not discard the mouse message. MA_NOACTIVATEANDEAT Does not activate the window, but discards the mouse message. When i tried using MA_NOACTIVATE, the focus problem (LineEdit Widget TitleBar shows that the widget is currently inactive) exists.

0
votes

You need to check for WM_GESTURE message. Also from this good article:

Note By default, you receive WM_GESTURE messages instead of WM_TOUCH messages. If you call RegisterTouchWindow, you will stop receiving WM_GESTURE messages.

So, if you still want to receive WM_TOUCH instead of WM_GESTURE, you can get the HWnd of the Qt window and pass it to the RegisterTouchWindow call.