[solved] How to catch mouse click event on titlebar area of QMainWindow?
-
wrote on 25 Aug 2011, 08:24 last edited by
Because the titlebar belongs to the OS,so I cant catch mouse click event on titlebar area of QMainWindow.
How to catch it? -
wrote on 25 Aug 2011, 08:42 last edited by
AFAIK, it is impossible or at least it
s impossible on Linux. Titlebar(window decoration) is separate program. Widgets inside doesn
t know anything about decoration. -
wrote on 25 Aug 2011, 08:49 last edited by
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.
-
wrote on 25 Aug 2011, 09:02 last edited by
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 clicksit seemed like possible in Embedded linux only
-
wrote on 25 Aug 2011, 09:23 last edited by
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.
-
wrote on 25 Aug 2011, 18:28 last edited by
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... -
wrote on 26 Aug 2011, 02:40 last edited by
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;
}@ -
wrote on 26 Aug 2011, 06:09 last edited by
[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 :-)
-
wrote on 26 Aug 2011, 06:28 last edited by
[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. -
wrote on 26 Aug 2011, 06:32 last edited by
Oh,I see. Thanks for the advice.
-
wrote on 26 Aug 2011, 06:47 last edited by
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
}
}
}@ -
7/11