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. Some questions about nativeEnentFilter using window messages
Forum Updated to NodeBB v4.3 + New Features

Some questions about nativeEnentFilter using window messages

Scheduled Pinned Locked Moved Solved General and Desktop
installnativeevnativeeventfilt
3 Posts 2 Posters 479 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.
  • M Offline
    M Offline
    Ming_tft
    wrote on last edited by
    #1

    Hello,I was working on a borderless window project recently, and there were some problems when using nativeEventFilter. When I received the message from windows in the nativeEventFilter function, the returned WM_NCCALCSIZE message was filtered, and then the border of my main window disappeared automatically. , I can’t find out what is causing the problem. Please help analyze why this is the case. I didn’t set FramelessWindowHint in my original window.

    main.cpp

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        FFTMainWindow w;
        w.show();
    
        NativeEventHelper helper(&w);
        // helper = new NativeEventHelper(w);
        a.installNativeEventFilter(&helper);
    
        return a.exec();
    }
    

    NativeEventHelper.cpp

    bool NativeEventHelper::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
    {
    #ifdef Q_OS_WIN
        if (eventType != "windows_generic_MSG")
            return false;
    
        MSG* msg = static_cast<MSG*>(message);
        QWidget* widget = QWidget::find(reinterpret_cast<WId>(msg->hwnd));
        // qDebug()<<"----widget----"<<widget;
        if (!widget)
            return false;
    
        switch (msg->message) {
    
        case WM_NCCALCSIZE: {
            qDebug()<<"----WM_NCCALCSIZE----";
            *result = 0;
            return true;
        }
        default:
            break;
    #endif
    
    return QWidget::nativeEvent(eventType, message, result);
    }
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Ming_tft said in Some questions about nativeEnentFilter using window messages:

      case WM_NCCALCSIZE: {
          qDebug()<<"----WM_NCCALCSIZE----";
          *result = 0;
          return true;
      

      the returned WM_NCCALCSIZE message was filtered, and then the border of my main window disappeared automatically. , I can’t find out what is causing the problem.

      You tell the caller that WM_NCCALCSIZE should be filtered.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      M 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        @Ming_tft said in Some questions about nativeEnentFilter using window messages:

        case WM_NCCALCSIZE: {
            qDebug()<<"----WM_NCCALCSIZE----";
            *result = 0;
            return true;
        

        the returned WM_NCCALCSIZE message was filtered, and then the border of my main window disappeared automatically. , I can’t find out what is causing the problem.

        You tell the caller that WM_NCCALCSIZE should be filtered.

        M Offline
        M Offline
        Ming_tft
        wrote on last edited by
        #3

        @Christian-Ehrlicher Thank you for your reply, it is helpful to me. In addition, I would like to ask another question. If I want to filter this way, I only want the main window to receive messages, but I don't want the child window control QWidget to receive messages. Can this be achieved? Or can it only be achieved by overloading the nativeEvent function on QMainWindow? Hope your reply

        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