gpt4 book ai didi

c++ - Qt 拖放 : cannot move when copy is enabled (Ubuntu Gnome)

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:49:10 24 4
gpt4 key购买 nike

我正在实现一个 View 和一个模型,我希望在其中支持内部移动项目(通过拖动)和复制项目(通过在拖动时按 Ctrl)。我已经按照说明完成了我需要做的一切。我已经设置了 mime 函数,我已经实现了 removeRows() 和 flags()。问题是当我拖动时,它默认为复制操作(我得到带有加号的箭头光标,它确实通过在模型中创建一个新项目来复制项目)。

我能看到的唯一区别是:如果我在 supportedDropActions() 中只返回 Qt::MoveAction,它只会移动。如果我返回 (Qt::CopyAction | Qt::MoveAction),它只会复制。

有什么想法吗?我希望它像 Nautilus (Gnome) 或 Windows 文件资源管理器中的文件一样工作:拖动移动图标,ctrl+拖动复制它们。

最佳答案

很抱歉,当我发现自己做错了什么时,没有继续回答这个问题。把我搞砸的代码在 QAbstractItemView::startDrag() 中:

if (d->defaultDropAction != Qt::IgnoreAction && (supportedActions & d->defaultDropAction))
defaultDropAction = d->defaultDropAction;
else if (supportedActions & Qt::CopyAction && dragDropMode() != QAbstractItemView::InternalMove)
defaultDropAction = Qt::CopyAction;

问题是我没有像 setDefaultDropAction( Qt::MoveAction ); 那样在小部件上设置 defaultDropAction 属性,因此 startDrag() 默认为 CopyAction。如果默认的 DropAction 是 Qt::MoveAction,那么您可以使用键盘 Ctrl 将正在进行的拖动切换为复制操作,这是我想要的行为。

我喜欢 Qt,但肯定有很多与拖放相关的令人困惑且有些交织在一起的属性。很容易得不到正确的属性组合。

底线:确保将 defaultDropAction 设置为 Qt::MoveAction

关于c++ - Qt 拖放 : cannot move when copy is enabled (Ubuntu Gnome),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11321982/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com