QListWidget派生:drop事件未触发

简兹

从QListWidget派生的小部件是窗口上的唯一小部件。函数“ setAcceptDrops(true);” 在其构造函数中使用“ event-> accept();” 在其“ dragEnterEvent”中调用。但是,无法触发其“ dropEvent”。请检查完整的源代码(使用Qt 5.12.0创建)在github.com/jianz-github/dropevent。

我在Qt Drop事件未触发时提出了一个问题这种情况应该是相同的,但事实并非如此。奇怪的。

在此先感谢您的帮助。

永乐

在这种情况下,解决方案是也覆盖该dragMoveEvent()方法。

listbox.h

#ifndef LISTBOX_H
#define LISTBOX_H

#include <QListWidget>
#include <QDropEvent>
#include <QDragEnterEvent>

class ListBox : public QListWidget
{
public:
    ListBox(QWidget *parent = nullptr);
protected:
    void dropEvent(QDropEvent *event) override;
    void dragEnterEvent(QDragEnterEvent *event) override;
    void dragMoveEvent(QDragMoveEvent *event) override;
};

#endif // LISTBOX_H

listbox.cpp

#include "listbox.h"
#include <QDebug>

ListBox::ListBox(QWidget *parent) : QListWidget (parent)
{
    setAcceptDrops(true);
}
void ListBox::dropEvent(QDropEvent *event)
{
    qDebug() << "dropEvent"<<event;
}
void ListBox::dragEnterEvent(QDragEnterEvent *event)
{
    event->acceptProposedAction();
}
void ListBox::dragMoveEvent(QDragMoveEvent *event)
{
    event->acceptProposedAction();
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章