How we can move the window by pressing and holding the mouse in window client area.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
QWidget::move()to move the window around. You detect when the user presses (withmousePressEvent()) and holds (withmouseMoveEvent()) the mouse and use those delta values to move the top-left corner os the window accordingly.Holding the mouse means to set a flag in
mousePressEvent()and to check that the flag is set inmouseMoveEvent(). CallglobalPos()on theQMouseEventpassed to get the position of the cursor and save it so that you know the last cursor position between calls tomouseMoveEvent(). Then you calculate the difference between the last position and the current position and move the window the delta distance.As an example add these to your window class:
And one way to implement them would be:
Now left clicking and holding in the client area will move the window around.