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



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



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



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



  • 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



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



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



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



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



  • Oh,I see. Thanks for the advice.



  • 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
    }
    }
    }@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.