How to catch a “drag windows”event in Qt?
-
Hi,everyone.
My friend is writing a program and he wants to make sure the mainwindow shouldn't be dragged out of the current screen ,so he wants to get a event function interface when dragging a widget to a new place.As we all know,the dragging window thing is divided into two steps:1.Click the left button.2)Drag the mouse into a new place(and release button).The qt has provide both single MouseEvent:QMousePressEvent and QMouseMoveEvent.But how to combine these two events into one ?
Thx for all of u.
-
Hi
Maybe use event filter ?
http://stackoverflow.com/questions/12953983/detect-end-of-movement-of-qmainwindow-qdialog-qt-4-8 -
@mrjj Hi,and thx for your advice.
My friend finds an interesting thing,when you drag the current mainwindow title bar,the event doesn't execute,however,when u drag the other part of the mainwindow,it worked.
So,the title bar is not a 'valid' part of a widget? How to include it into the effective window?
-
Hi
when you drag in caption its not a normal event
its WM_NCHITTEST
Its handled by the OS and as far as i know there is
not default way of catching them.so no the border is called a windows decoration and its handled by the OS/windows manager.
please see here
https://forum.qt.io/topic/8922/solved-how-to-catch-mouse-click-event-on-titlebar-area-of-qmainwindow/2bool gwMainWindow::winEvent ( MSG * msg, long * result )
{
if (msg->message == WM_NCLBUTTONDOWN)
{
//here can catch the leftmousedown event on titlebar
}return false;
}NOTE , this ONLY works on windows!