作者:sdfdsafgafsdf | 来源:互联网 | 2023-09-12 10:14
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:
当我运行此代码并拖放一些项目时,它看起来像这样:
Why is the dragged item removed? Any ideas of what I'm missing?
为什么删除拖动的项目?我缺少什么想法?
2 个解决方案