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

查看:400
本文介绍了在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与QMainWindow成员一起嵌入到我的DockArea的新实例中.现在,我拦截拖动的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);
}

我发现了在Internet上QMainWindows之间拖放QDockWidgets的不同建议:

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

1)重新育儿-这就是我正在尝试的atm

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

2)QDrag-不适用于我,异步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.

Ich发现此论坛帖子处理的是相同的问题: 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).当您还希望允许在窗口中重新排列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天全站免登陆