热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

QListWidget中的InternalMove使项目消失-InternalMoveinQListWidgetmakesitemdisappear

Imtryingtomakedraganddropinsideatreewidgetworktobeabletomoveitemsaroundinsideth

I'm trying to make drag and drop inside a tree widget work to be able to move items around inside that widget. I've managed to make items draggable but when I release the mouse button the item disappears. To narrow it down I've tried the following example (taken from another post here on SO) which has the same issues as my tree widget in Qt 5.4 on Windows 7:

我正在尝试拖放树小部件工作,以便能够在该小部件内移动项目。我已设法使物品可拖动,但当我释放鼠标按钮时,该项目消失。为了缩小范围,我尝试了以下示例(取自SO上的另一篇文章),它与我在Windows 7上的Qt 5.4中的树小部件具有相同的问题:

#include 

int main(int argc, char **argv)
{
    QApplication a(argc, argv);

    QListWidget lw;

    for(int i = 1; i <10; ++i)
        lw.addItem(new QListWidgetItem(QString("Item %1").arg(i)));
    lw.setDragEnabled(true); // ***
    lw.viewport()->setAcceptDrops(true); // ***
    lw.setDefaultDropAction(Qt::MoveAction); // ***
    lw.setDropIndicatorShown(true); // ***

    lw.setDragDropMode(QAbstractItemView::InternalMove);

    lw.show();

    a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
    a.exec();
}

When I run this code and drag/drop some items it looks like this: dragdrop

当我运行此代码并拖放一些项目时,它看起来像这样:

Why is the dragged item removed? Any ideas of what I'm missing?

为什么删除拖动的项目?我缺少什么想法?

2 个解决方案

#1


3  

I have changed one line in your code:

我在代码中更改了一行:

lw.setDefaultDropAction(Qt::TargetMoveAction);

and now it works fine (Qt 5.4.1 Windows 8, Visual Studio 2013).

现在它工作正常(Qt 5.4.1 Windows 8,Visual Studio 2013)。

#2


3  

It's a bug in Qt 5.4.1, your code work correctly on Qt 4.8.6

这是Qt 5.4.1中的一个错误,您的代码在Qt 4.8.6上正常工作


推荐阅读
author-avatar
sdfdsafgafsdf
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有