Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Frameless window dragging issue
QtWS25 Last Chance

Frameless window dragging issue

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 18.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    thehilmisu
    wrote on last edited by A Former User
    #1

    Hi everyone,
    I am developing an qt gui application and i have set the window flag to @Qt::FramelessWİndowHint@ and i have set the mainwindow stylesheet as i wanted. But i cannot move the window without the window frames.

    Is there any way to solve it ?

    Thanks in advance,

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sanja1989
      wrote on last edited by A Former User
      #2

      Add to window .h file:

      private:
          void mousePressEvent(QMouseEvent *event);
          void mouseMoveEvent(QMouseEvent *event);
          int m_nMouseClick_X_Coordinate;
          int m_nMouseClick_Y_Coordinate;
      

      And this to .cpp file:

      void MainWindow::mousePressEvent(QMouseEvent *event) {
          m_nMouseClick_X_Coordinate = event->x();
          m_nMouseClick_Y_Coordinate = event->y();
      }
      
      void MainWindow::mouseMoveEvent(QMouseEvent *event) {
          move(event->globalX()-m_nMouseClick_X_Coordinate,event->globalY()-m_nMouseClick_Y_Coordinate);
      }
      

      This is quick answer. Code may grow up if you have resizing elements or problems with dragging when mouse pressed on window child elements.

      1 Reply Last reply
      3
      • V Offline
        V Offline
        Vaquita Tim
        wrote on last edited by
        #3

        I've not done this, but I can only imagine that you would have to provide your own code to move the window. As it is, a frameless window has no UI component with which the user can imagine that the window can be moved.

        Or is that not what you meant ?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sanja1989
          wrote on last edited by
          #4

          Of course you need to add code for handling mouse events.
          I think it is good idea to make something like title bar for moving the window.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            thehilmisu
            wrote on last edited by
            #5

            Thank you sanja1989 your code works perfectly.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved