1

I have searched the web for possibilities to realize this but haven't found a solution. Is there a simple way of removing an item from the list that is dropped on a non-receiving area or even outside the application's window?

So far I accept the delete key for removing items by means of a shortcut:

QShortcut *shortcut = new QShortcut(QKeySequence(Qt::Key_Delete), myList);
shortcut->setContext(Qt::WidgetShortcut);
connect(shortcut, SIGNAL(activated()), this, SLOT(deleteSelection()));

But since I add items to the list via drag and drop, I would like to be able to remove them in the same way, too. The items in the list can also be ordered via drag and drop.

Any hints or links are appreciated.

4

1 回答 1

1

这似乎对我有用:

  • 拖放操作应该是Qt::MoveAction
  • QListWidget确保(例如, )的父级QDialog具有以下内容:
    • dragEnterEvent()实施的
    • dropEvent()已实现(忽略此处的 mime 数据)
    • setAcceptDrops(true);

忽略 a 中的 mime 数据dropEvent()应该Qt::MoveAction等同于项目删除操作。

祝你好运!

于 2012-02-29T21:58:51.940 回答