August 25, 2011

yunxiaodong yunxiaodong
Lab Rat
23 posts

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

 Signature 

I love peace.

10 replies

August 25, 2011

task_struct task_struct
Hobby Entomologist
344 posts

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.

 Signature 

“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.”
- Linus Torvalds

August 25, 2011

cincirin cincirin
Ant Farmer
387 posts

I don’t know with Qt framework, but on windows you can catch the WM_NCHITTEST [msdn.microsoft.com]).aspx message, and check if HTCAPTION is the return value of DefWindowProc.

August 25, 2011

yunxiaodong yunxiaodong
Lab Rat
23 posts

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

 Signature 

I love peace.

August 25, 2011

Andre Andre
Area 51 Engineer
6031 posts

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.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

August 25, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

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…

 Signature 

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

August 26, 2011

yunxiaodong yunxiaodong
Lab Rat
23 posts

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

  1. bool gwMainWindow::winEvent ( MSG * msg, long * result )
  2. {
  3.  if (msg->message == WM_NCLBUTTONDOWN)
  4.  {
  5.   //here can catch the leftmousedown event on titlebar
  6.  }
  7.  
  8.  return false;
  9. }

 Signature 

I love peace.

August 26, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

yunxiaodong wrote:
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; }@

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

 Signature 

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

August 26, 2011

cincirin cincirin
Ant Farmer
387 posts

yunxiaodong wrote:

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

return false; }@
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.

August 26, 2011

yunxiaodong yunxiaodong
Lab Rat
23 posts

Oh,I see. Thanks for the advice.

 Signature 

I love peace.

August 26, 2011

yunxiaodong yunxiaodong
Lab Rat
23 posts

and it should be like this

  1. bool gwMainWindow::winEvent ( MSG * msg, long * result )
  2. {
  3.     if (msg->message == WM_NCLBUTTONDOWN)
  4.     {
  5.          int nHittest = (INT) msg->wParam;
  6.          if (nHittest == HTCAPTION)
  7.              {
  8.                //here catch the lbuttondown event only on titlebar
  9.              }
  10.     }
  11. }

 Signature 

I love peace.

 
  ‹‹ Getting screen information in both desktop and mobile      [SOLVED] Help me with creating a Groupbox with listwidget and buttons! ››

You must log in to post a reply. Not a member yet? Register here!