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. Qt disable clicking on the left corner icon
Forum Updated to NodeBB v4.3 + New Features

Qt disable clicking on the left corner icon

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 1.2k Views 4 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.
  • K Offline
    K Offline
    kocka
    wrote on last edited by
    #1

    I am using win10 and qt5.

    How could I disable display the pop up menu, when I click on the left corner icon? So I want everything to remain the same except disable the pop up.

    qt.png

    I have tried setWindowFlags() with a loads of flags, but it does not helped for me.

    raven-worxR 1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #6

      There's no way to do that in Qt alone, but, since it's Windows specific anyway, you can use the native api. Just override the native event handler in your window class and ignore specific Windows messages:

      bool YourWindowClass::nativeEvent(const QByteArray& eventType, void* message, long* result)
      {
          MSG* msg = static_cast<MSG*>(message);
      
          // Disables menu when left clicked on icon
          if (msg->message == WM_SYSCOMMAND && (msg->wParam & 0xFFF0) == SC_MOUSEMENU)
          {
              *result = 0;
              return true;
          }
      
          // Disables menu when right clicked anywhere on the title bar
          if (msg->message == WM_NCRBUTTONDOWN || msg->message == WM_NCRBUTTONUP)
          {
              *result = 0;
              return true;
          }
      
          return QMainWindow::nativeEvent(eventType, message, result);
      }
      

      You need to #include <Windows.h> for these WinAPI types and constants.

      K 1 Reply Last reply
      4
      • K kocka

        I am using win10 and qt5.

        How could I disable display the pop up menu, when I click on the left corner icon? So I want everything to remain the same except disable the pop up.

        qt.png

        I have tried setWindowFlags() with a loads of flags, but it does not helped for me.

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #2

        @kocka
        this is a Windows Window Manager feature and out of the scope of Qt.
        I believe thats not possible afterall.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        K 1 Reply Last reply
        0
        • raven-worxR raven-worx

          @kocka
          this is a Windows Window Manager feature and out of the scope of Qt.
          I believe thats not possible afterall.

          K Offline
          K Offline
          kocka
          wrote on last edited by kocka
          #3

          @raven-worx

          w.setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint); makes the following:

          qt.png
          so I belive that there is a solution.

          If I also add Qt::WindowMinimizeButtonHint , the whole bar show because Qt::WindowMinimizeButtonHint , Qt::WindowCloseButtonHint ..... implies Qt::WindowSystemMenuHint for it to work.

          raven-worxR 1 Reply Last reply
          0
          • K kocka

            @raven-worx

            w.setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint); makes the following:

            qt.png
            so I belive that there is a solution.

            If I also add Qt::WindowMinimizeButtonHint , the whole bar show because Qt::WindowMinimizeButtonHint , Qt::WindowCloseButtonHint ..... implies Qt::WindowSystemMenuHint for it to work.

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #4

            @kocka
            if thats ok for you.
            i assumed you wanted to keep the icon.

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            K 1 Reply Last reply
            0
            • raven-worxR raven-worx

              @kocka
              if thats ok for you.
              i assumed you wanted to keep the icon.

              K Offline
              K Offline
              kocka
              wrote on last edited by
              #5

              @raven-worx

              I want to keep the icon, and I want to keep the close up button as well, I just mentioned, this method is does not working.

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

                There's no way to do that in Qt alone, but, since it's Windows specific anyway, you can use the native api. Just override the native event handler in your window class and ignore specific Windows messages:

                bool YourWindowClass::nativeEvent(const QByteArray& eventType, void* message, long* result)
                {
                    MSG* msg = static_cast<MSG*>(message);
                
                    // Disables menu when left clicked on icon
                    if (msg->message == WM_SYSCOMMAND && (msg->wParam & 0xFFF0) == SC_MOUSEMENU)
                    {
                        *result = 0;
                        return true;
                    }
                
                    // Disables menu when right clicked anywhere on the title bar
                    if (msg->message == WM_NCRBUTTONDOWN || msg->message == WM_NCRBUTTONUP)
                    {
                        *result = 0;
                        return true;
                    }
                
                    return QMainWindow::nativeEvent(eventType, message, result);
                }
                

                You need to #include <Windows.h> for these WinAPI types and constants.

                K 1 Reply Last reply
                4
                • Chris KawaC Chris Kawa

                  There's no way to do that in Qt alone, but, since it's Windows specific anyway, you can use the native api. Just override the native event handler in your window class and ignore specific Windows messages:

                  bool YourWindowClass::nativeEvent(const QByteArray& eventType, void* message, long* result)
                  {
                      MSG* msg = static_cast<MSG*>(message);
                  
                      // Disables menu when left clicked on icon
                      if (msg->message == WM_SYSCOMMAND && (msg->wParam & 0xFFF0) == SC_MOUSEMENU)
                      {
                          *result = 0;
                          return true;
                      }
                  
                      // Disables menu when right clicked anywhere on the title bar
                      if (msg->message == WM_NCRBUTTONDOWN || msg->message == WM_NCRBUTTONUP)
                      {
                          *result = 0;
                          return true;
                      }
                  
                      return QMainWindow::nativeEvent(eventType, message, result);
                  }
                  

                  You need to #include <Windows.h> for these WinAPI types and constants.

                  K Offline
                  K Offline
                  kocka
                  wrote on last edited by kocka
                  #7

                  @Chris-Kawa

                  Thanks that works for me.

                  If I double click on the icon the window close itself, could you show me the solution? Thanks in advance.

                  Chris KawaC 1 Reply Last reply
                  0
                  • K kocka

                    @Chris-Kawa

                    Thanks that works for me.

                    If I double click on the icon the window close itself, could you show me the solution? Thanks in advance.

                    Chris KawaC Online
                    Chris KawaC Online
                    Chris Kawa
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    @kocka It's similar to the SC_MOUSEMENU check, but the param in that case is SC_CLOSE. The problem is this would also disable closing via clicking the X button, ALT+F4 or via context menu on the taskbar, so you'd need to figure out what caused this message. You could for example check the cursor position to see if it's above the corner where the icon is.

                    Out of curiosity - why are trying to do all this? These features are a standard Windows behavior and disabling them is generally not a good idea. Your app may seem broken to people used to having those features on every other app.

                    K 1 Reply Last reply
                    2
                    • Chris KawaC Chris Kawa

                      @kocka It's similar to the SC_MOUSEMENU check, but the param in that case is SC_CLOSE. The problem is this would also disable closing via clicking the X button, ALT+F4 or via context menu on the taskbar, so you'd need to figure out what caused this message. You could for example check the cursor position to see if it's above the corner where the icon is.

                      Out of curiosity - why are trying to do all this? These features are a standard Windows behavior and disabling them is generally not a good idea. Your app may seem broken to people used to having those features on every other app.

                      K Offline
                      K Offline
                      kocka
                      wrote on last edited by kocka
                      #9

                      @Chris-Kawa

                      Actually I am learing Qt, and I find this pop up and double click stuff, and I was curious how could I disable it.

                      This message disable double left click within nonclient area.

                      if(msg->message == WM_NCLBUTTONDBLCLK)
                      {
                           *result = 0;
                           return true;
                      }
                      
                      Chris KawaC 1 Reply Last reply
                      0
                      • K kocka

                        @Chris-Kawa

                        Actually I am learing Qt, and I find this pop up and double click stuff, and I was curious how could I disable it.

                        This message disable double left click within nonclient area.

                        if(msg->message == WM_NCLBUTTONDBLCLK)
                        {
                             *result = 0;
                             return true;
                        }
                        
                        Chris KawaC Online
                        Chris KawaC Online
                        Chris Kawa
                        Lifetime Qt Champion
                        wrote on last edited by
                        #10

                        @kocka Ok, so this is not very Qt related. Qt mostly deals with the client area of the window. The frame of the window and stuff on it are managed by the native platform specific window manager. Qt only interacts with it in limited scenarios that are more or less cross-platform, so like changing title or window type (dialog, popup, toolbox etc.). The more platform specific stuff, like those context menus, are not usually exposed through Qt interface directly, but you can dig into them through native APIs. This of course makes your code not cross-platform, so in a serious project stuff like this would be put in a platform specific #ifdef.

                        K 1 Reply Last reply
                        3
                        • Chris KawaC Chris Kawa

                          @kocka Ok, so this is not very Qt related. Qt mostly deals with the client area of the window. The frame of the window and stuff on it are managed by the native platform specific window manager. Qt only interacts with it in limited scenarios that are more or less cross-platform, so like changing title or window type (dialog, popup, toolbox etc.). The more platform specific stuff, like those context menus, are not usually exposed through Qt interface directly, but you can dig into them through native APIs. This of course makes your code not cross-platform, so in a serious project stuff like this would be put in a platform specific #ifdef.

                          K Offline
                          K Offline
                          kocka
                          wrote on last edited by kocka
                          #11

                          @Chris-Kawa

                          Okey, I know that this is a windows stuff, and thanks for you help.

                          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