在 QMainWindows 之间拖动 QDockWidgets [英] Dragging QDockWidgets between QMainWindows

查看:20
本文介绍了在 QMainWindows 之间拖动 QDockWidgets的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于在 QMainWindows 之间拖动 QDockWidgets 的问题.我有一个具有不同DockAreas"的应用程序,它有一个带有一个或多个 QDockWidgets 的 QMainWindow 成员.此外,我想让 QDockWidgets 可以拖放到其他已经浮动的 QDockWidgets 中(不是选项卡!).

I have a question regarding dragging QDockWidgets between QMainWindows. I have an application with different "DockAreas" which have a QMainWindow member with one or more QDockWidgets. Additionally, I want to make QDockWidgets drag-and-droppable into other, already floating QDockWidgets (not tabbed!).

为了在拖放时获得良好的悬停效果,浮动 QDockWidgets 嵌入到我的 DockArea 的新实例中,其中包含 QMainWindow 成员.现在,我拦截了拖动的 QDockWidget 的 mousemove 事件,并在它悬停在我的 DockArea 的另一个 QMainWindow 上时更改其父级.不幸的是,这会导致崩溃,并且看起来这个 QDockWidget 所在的原始 QLayoutItem 已经消失了.

To have the nice hover-effect upon drag-and-drop, the floating QDockWidgets are embedded in a new instance of my DockArea with the QMainWindow member. Now I intercept the mousemove event of the dragged QDockWidget and change its parent when it hovers over another QMainWindow of my DockArea. Unfortunately, this causes a crash and it looks like the original QLayoutItem, where this QDockWidget was in, is gone.

void QDockWidgetPrivate::moveEvent(QMoveEvent *event)
{
    // ...
    // now this widgetItem member of state is kaputt
    layout->hover(state->widgetItem, globalMousePos);
}

我在网上找到了在 QMainWindows 之间拖放 QDockWidgets 的不同建议:

I found different suggestions for dragging-dropping QDockWidgets between QMainWindows on the internet:

1) 重新养育子女 - 这就是我正在尝试的方法

1) Re-parenting - that's what I am trying atm

2) QDrag - 对我不起作用,async exec() 破坏了我的应用程序,最后我必须重新设置父项

2) QDrag - did not work for me, async exec() breaks my application and at the end I have to reparent anyway

3) 调用新 QMainWindow 的 addDockWidget(...) - 停靠 QDockWidget,我必须让它再次浮动并以某种方式继续拖动"

3) Call addDockWidget(...) of the new QMainWindow - docks the QDockWidget and I would have to make it floating again and somehow "continue the dragging"

我愿意接受任何新的建议 :) 提前谢谢您!

I am open to any new suggestions :) Thank you in advance!

推荐答案

我现在也遇到同样的问题,想分享一下.

I'm wrestling with the same Problem right now and want to share.

我发现这个论坛帖子处理同样的问题:http://www.qtcentre.org/threads/41847-Dragging-QDockWidgets-between-QMainWindows然而,这个解决方案是有缺陷的:如果你允许 Dockables 浮动,它就不能正常工作.当您进入另一个窗口并仍然拖动 QDockWidget 时,enterEvent 并不会真正触发.它只在发布后触发.

Ich found this forum post dealing with the same problem: http://www.qtcentre.org/threads/41847-Dragging-QDockWidgets-between-QMainWindows This solution is however flawed: it doesn't work properly if you allow the Dockables to be floating. And the enterEvent does not actually trigger when you enter the other window and still dragging the QDockWidget. It only triggers after release.

我也打算进行重新育儿 (1).当您还希望允许在 Window 内重新排列 QDockWidget 时,QDrag 似乎有问题.

I'm also going for the reparenting (1). QDrag seems problematic when you also want to allow rearranging the QDockWidget within the Window.

我认为可以通过对拖动的 QDockWidget 的放下/释放做出反应来正确地做到这一点.但我找不到这方面的事件或信号.

I think one would correctly do this by reacting to the drop/release of the dragged QDockWidget. But I can't find an event or signal for this.

这篇关于在 QMainWindows 之间拖动 QDockWidgets的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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