Qt-如何粘贴两个窗口并将它们一起移动? [英] Qt - how to glue two windows and move them together?

查看:63
本文介绍了Qt-如何粘贴两个窗口并将它们一起移动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像qmmp(Qt)音乐播放器ui的设计一样,这两个或三个窗口实际上位于同一窗口中,因为只有停靠图标,并且这些窗口可以一起移动并相互连接.

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 attach to each other.

我阅读了源代码,似乎使用了 QDockWidget .但是我真的不知道如何获得它的细节.

I read the source code, it seems use QDockWidget. But I really don't know the details how to get it.

推荐答案

在您手动移动辅助窗口(在本例中为播放列表)时,您会检查手动移动的结束位置,以及它是否位于主要窗口的边缘窗口,只需将其位置绑定到主窗口的位置和尺寸即可.

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.

这篇关于Qt-如何粘贴两个窗口并将它们一起移动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆