Important: Please read the Qt Code of Conduct -

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

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



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


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

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

           return true;


      return false;@

    3. IDM_ABOUTBOX is defined as below
      @// IDM_ABOUTBOX must be in the system command range
      // 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 "":

Log in to reply