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] How to catch mouse click event on titlebar area of QMainWindow?
QtWS25 Last Chance

[solved] How to catch mouse click event on titlebar area of QMainWindow?

Scheduled Pinned Locked Moved General and Desktop
11 Posts 5 Posters 12.1k 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.
  • Y Offline
    Y Offline
    yunxiaodong
    wrote on last edited by
    #1

    Because the titlebar belongs to the OS,so I cant catch mouse click event on titlebar area of QMainWindow.
    How to catch it?

    I love peace.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      task_struct
      wrote on last edited by
      #2

      AFAIK, it is impossible or at least its impossible on Linux. Titlebar(window decoration) is separate program. Widgets inside doesnt know anything about decoration.

      "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

      • Linu...
      1 Reply Last reply
      0
      • C Offline
        C Offline
        cincirin
        wrote on last edited by
        #3

        I don't know with Qt framework, but on windows you can catch the "WM_NCHITTEST":http://msdn.microsoft.com/en-us/library/ms645618(v=vs.85).aspx message, and check if HTCAPTION is the return value of DefWindowProc.

        1 Reply Last reply
        0
        • Y Offline
          Y Offline
          yunxiaodong
          wrote on last edited by
          #4

          In Qt Assistant:

          The QDecoration class is a base class for window decorations in Qt for Embedded Linux
          Note that this class is non-portable and only available in Qt for Embedded Linux.
          Reimplement the regionClicked() and regionDoubleClicked() functions to respond to mouse clicks

          it seemed like possible in Embedded linux only

          I love peace.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            No, in Embedded linux. That is: none desktop, where Qt plays its own window manager. I doubt that is the use case that you have.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #6

              Hi,

              you have to deal with OS messages for that. On windows, you can use QWidget::winEvent() to catch those events, for linux tghere are similar message handlers. I am sure also for mac.
              The only thing you additionally need is which messages to catch...

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • Y Offline
                Y Offline
                yunxiaodong
                wrote on last edited by
                #7

                Gerolf and cincirin, finally, As you suggested problems have been solved.

                @bool gwMainWindow::winEvent ( MSG * msg, long * result )
                {
                if (msg->message == WM_NCLBUTTONDOWN)
                {
                //here can catch the leftmousedown event on titlebar
                }

                return false;
                }@

                I love peace.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  giesbert
                  wrote on last edited by
                  #8

                  [quote author="yunxiaodong" date="1314326449"]Gerolf and cincirin, finally, As you suggested problems have been solved.

                  @bool gwMainWindow::winEvent ( MSG * msg, long * result )
                  {
                  if (msg->message == WM_NCLBUTTONDOWN)
                  {
                  //here can catch the leftmousedown event on titlebar
                  }

                  return false;
                  }@[/quote]

                  But, if you do some platform independant stuff, you need to do more :-)

                  Nokia Certified Qt Specialist.
                  Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    cincirin
                    wrote on last edited by
                    #9

                    [quote author="yunxiaodong" date="1314326449"]
                    @bool gwMainWindow::winEvent ( MSG * msg, long * result )
                    {
                    if (msg->message == WM_NCLBUTTONDOWN)
                    {
                    //here can catch the leftmousedown event on titlebar
                    }

                    return false;
                    }@[/quote]
                    With WM_NCLBUTTONDOWN notify message you're not sure click on title bar. Indeed title bar is non client area, but a window, outside the titlebar has other non-client area.

                    1 Reply Last reply
                    0
                    • Y Offline
                      Y Offline
                      yunxiaodong
                      wrote on last edited by
                      #10

                      Oh,I see. Thanks for the advice.

                      I love peace.

                      1 Reply Last reply
                      0
                      • Y Offline
                        Y Offline
                        yunxiaodong
                        wrote on last edited by
                        #11

                        and it should be like this

                        @bool gwMainWindow::winEvent ( MSG * msg, long * result )
                        {
                        if (msg->message == WM_NCLBUTTONDOWN)
                        {
                        int nHittest = (INT) msg->wParam;
                        if (nHittest == HTCAPTION)
                        {
                        //here catch the lbuttondown event only on titlebar
                        }
                        }
                        }@

                        I love peace.

                        1 Reply Last reply
                        0
                        • Dummie1138D Dummie1138 referenced this topic on

                        • Login

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