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. [SOLVED] Add custom actions for menu shown upon clicking the title bar icon

[SOLVED] Add custom actions for menu shown upon clicking the title bar icon

Scheduled Pinned Locked Moved General and Desktop
3 Posts 1 Posters 3.2k 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.
  • B Offline
    B Offline
    bharath144
    wrote on 2 Sept 2014, 10:07 last edited by
    #1

    Hello all,

    I have a need to add a custom action (say 'About' clicking which a messagebox needs to be displayed) in the context menu (system menu) shown when the icon on the title bar of a QDialog is clicked. How do I achieve this?

    !http://i.msdn.microsoft.com/dynimg/IC163369.png!

    Regards,
    Bharath

    Cheers!
    ಮೈ ಗೋ ಭರತ ನಾರಾಯಣ
    Bharath Narayan M G

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bharath144
      wrote on 2 Sept 2014, 10:59 last edited by
      #2

      I tried doing this.

      @ setContextMenuPolicy(Qt::CustomContextMenu);
      connect(this, SIGNAL(customContextMenuRequested(QPoint)),
      this, SLOT(addContextMenuAction(QPoint)));@

      In this case the slot isn't getting called when I click on the window title icon or right click any where on the title bar (which displays the popup menu with Maximize, Minimize and Close actions).

      Regards,
      Bharath

      Cheers!
      ಮೈ ಗೋ ಭರತ ನಾರಾಯಣ
      Bharath Narayan M G

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bharath144
        wrote on 8 Sept 2014, 12:56 last edited by
        #3

        Hello,

        I found the way to solve this. The solution is specific to windows platform. Here's what I did.

        1. Add a separator and 'About' text to the system menu
          @HMENU sysMenu = ::GetSystemMenu((HWND) winId(), FALSE);
          if (sysMenu != NULL) {
          ::AppendMenuA(sysMenu, MF_SEPARATOR, 0, 0);
          ::AppendMenuA(sysMenu, MF_STRING, IDM_ABOUTBOX, "About");
          }@

        2. Override QWidget::nativeEvent (in Qt 5.x) or QWidget::winEvent (in Qt 4.x) and handle the event
          @ MSG msg = (MSG) message;
          Q_UNUSED(type)

          if (msg->message == WM_SYSCOMMAND) {
          if ((msg->wParam & 0xfff0) == IDM_ABOUTBOX) {
          *result = 0;
          // Show the About dialog
          displayAboutInformation();

               return true;
           }
          

          }

          return false;@

        3. IDM_ABOUTBOX is defined as below
          @// IDM_ABOUTBOX must be in the system command range
          // (IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX)
          // and (IDM_ABOUTBOX < 0xF000)
          #define IDM_ABOUTBOX 0x0010@

        4. Include user32 in the pro file
          @LIBS += -lUser32@

        I got this information from an older thread "https://qt-project.org/forums/viewthread/21165":https://qt-project.org/forums/viewthread/21165

        Cheers!
        ಮೈ ಗೋ ಭರತ ನಾರಾಯಣ
        Bharath Narayan M G

        1 Reply Last reply
        0

        2/3

        2 Sept 2014, 10:59

        • Login

        • Login or register to search.
        2 out of 3
        • First post
          2/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved