-1

So i have this project with Frameless windows and in order to move them around the screen made such functions for every window:

window.h

private:
    Ui::MainWindow *ui;
    void main_mousePressEvent(QMouseEvent *event);
    void main_mouseMoveEvent(QMouseEvent *event);
    int m_nMouseClick_X_Coordinate;
    int m_nMouseClick_Y_Coordinate;

window.cpp

void MainWindow::main_mousePressEvent(QMouseEvent *event) {
    m_nMouseClick_X_Coordinate = event->position().x();
    m_nMouseClick_Y_Coordinate = event->position().y();
    //qDebug() << m_nMouseClick_X_Coordinate << " 1 " << m_nMouseClick_Y_Coordinate;
}

void MainWindow::main_mouseMoveEvent(QMouseEvent *event) {
    move(event->globalPosition().x()-m_nMouseClick_X_Coordinate,event->globalPosition().y()-m_nMouseClick_Y_Coordinate);
    //qDebug() << m_nMouseClick_X_Coordinate << " 2 " << m_nMouseClick_Y_Coordinate;
}

and that worked very well until i rebooted computer and run the program again... for some reason windows don't move now, any ideas what happened?

P.S. Qt ver. - 6

1 Answers1

0

Maybe a stupid question, but have you enabled mouse tracking? eg. setMouseTracking(true); in the window constructor.

Also, with your implementation, the window will move constantly even when you are not pressing the mouse. The way I would do it is to override two functions: onMousePressEvent() and onMouseReleaseEvent(), and create a variable isMousePressed which will be checked in the mouseMoveEvent() before moving the window.

splaytreez
  • 552
  • 5
  • 13