Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to catch a “drag windows”event in Qt?
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.
Maybe use event filter ?
@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?
when you drag in caption its not a normal event
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.
bool gwMainWindow::winEvent ( MSG * msg, long * result )
if (msg->message == WM_NCLBUTTONDOWN)
//here can catch the leftmousedown event on titlebar
NOTE , this ONLY works on windows!
@mrjj thx very much and I will try to use winapi way to solve it.