Move a window by clicking an internal widget instead of title bar

后端 未结 2 494
说谎
说谎 2021-01-28 19:02

In Windows when I create a QMainWindow I can move it around the screen by clicking the title bar and dragging it.

In my application I\'ve hidden the title bar by using <

2条回答
  •  面向向阳花
    2021-01-28 19:42

    You just need to implement the necessary mouse event handling by overwriting MyWidget's mousePressEvent(), mouseMoveEvent() and mouseReleaseEvent() handlers.

    1. Detect the mouse down, get current mouse position
    2. While moving, get current mouse position, calculate difference, save new position, move window by diff

    You can get the window (top level widget) from inside MyWidget through the window() method.

提交回复
热议问题