[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 it
s impossible on Linux. Titlebar(window decoration) is separate program. Widgets inside doesn
t 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 clicksit seemed like possible in Embedded linux only
-
-
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
}
}
}@ -
D Dummie1138 referenced this topic on