Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6772071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:30:22+00:00 2026-05-26T15:30:22+00:00

How we can move the window by pressing and holding the mouse in window

  • 0

How we can move the window by pressing and holding the mouse in window client area.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:30:22+00:00Added an answer on May 26, 2026 at 3:30 pm

    Use QWidget::move() to move the window around. You detect when the user presses (with mousePressEvent()) and holds (with mouseMoveEvent()) 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 in mouseMoveEvent(). Call globalPos() on the QMouseEvent passed to get the position of the cursor and save it so that you know the last cursor position between calls to mouseMoveEvent(). 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:

    class Window : public QWidget {
    
    // ..
    
    protected:
      void mousePressEvent(QMouseEvent *event);
      void mouseReleaseEvent(QMouseEvent *event);  
      void mouseMoveEvent(QMouseEvent *event);                                          
    
    private:
      bool down;
      QPoint lastPos;
    };
    

    And one way to implement them would be:

    void Window::mousePressEvent(QMouseEvent *event) {
      if (event->button() == Qt::LeftButton) {
        down = true;
        lastPos = event->globalPos();  
      }
    
      QWidget::mousePressEvent(event);  
    }
    
    void Window::mouseReleaseEvent(QMouseEvent *event) {
      down = false;  
      QWidget::mouseReleaseEvent(event);  
    }
    
    void Window::mouseMoveEvent(QMouseEvent *event) {
      if (down) {
        QPoint curPos = event->globalPos();
        if (curPos != lastPos) {
          QPoint diff = (lastPos - curPos);
          move(pos() - diff);
          lastPos = curPos;
        }
      }
    
      QWidget::mouseMoveEvent(event);
    }
    

    Now left clicking and holding in the client area will move the window around.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I extend the distance the mouse can move in an OpenGL window?
so I have created this popup window with a custom move and sizing, pressing
This question solves half of my problem because my sliding window can move outside
Is there any control that can move the Window without the Title bar(Top one)/No
I can not move the border control while the mouse is outside the border
If I open a browser dialog with window.open , can I move HTML DOM
how can create a windows move maker like application in vb.net.... if we want
If I have several OS-X Terminal.app windows open, how can I move one Terminal
I can move my pointer up and down one line with my arrow key
I'm currently trying to create a desktop like homepage where using can move around

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.