Qt - how to glue two windows and move them together?

前端 未结 1 1386
眼角桃花
眼角桃花 2021-01-27 11:53

Like the qmmp(Qt) music player ui design, these two or three windows are in fact in the same window, because there is only a dock icon, and these windows can move together and a

相关标签:
1条回答
  • 2021-01-27 12:26

    When you manually move the secondary window, in this case - the playlist, you check where the manual move ends, and if it is on the edges of the primary window, you glue it by simply binding its position to the position and dimensions of the primary window.

    Since the window position and dimensions are properties, they have notification signals, so you can connect those to a function that automatically moves the glued window.

    And finally, when you attempt to manually move the secondary window, you un-glue by disconnecting.

    You can easily support offset gluing instead of a purely horizontal or vertical one, by calculating and storing the positioning offset and applying it on every primary window move.

    If the drop happens within a given threshold of the primary window you can snap to the edge. If you factor in the mouse position relative to the dragged window, you can even snap particular edges together.

    0 讨论(0)
提交回复
热议问题