Frameless window dragging issue



  • 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,



  • 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.



  • 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 ?



  • 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.



  • Thank you sanja1989 your code works perfectly.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.