Hi,

I have a problem concerning drag'n'drop and QTableWidget. I have subclassed QTableWidget and implemented drag'n'drop by reimplementing dragEnterEvent, dragMoveEvent and dropEvent. It works as I expect. But if I place a QLabel as a child on the QTableWidget, I cannot drop items on the QLabel ( I want to receive the dropevent in QTableWidget). Here is some sample code

table.h
Qt Code:
  1. #ifndef TABLE_H
  2. #define TABLE_H
  3.  
  4. #include <QTableWidget>
  5.  
  6. class Table : public QTableWidget
  7. {
  8. Q_OBJECT
  9. public:
  10. explicit Table(QWidget *parent = 0);
  11.  
  12. protected:
  13. void dragEnterEvent(QDragEnterEvent *event);
  14. void dragMoveEvent(QDragMoveEvent *event);
  15. void dropEvent(QDropEvent *event);
  16. };
  17.  
  18. #endif // TABLE_H
To copy to clipboard, switch view to plain text mode 

table.cpp
Qt Code:
  1. #include "table.h"
  2. #include <QLabel>
  3. #include <QDebug>
  4. #include <QDragEnterEvent>
  5. #include <QDragMoveEvent>
  6.  
  7. Table::Table(QWidget *parent) :
  8. QTableWidget(parent)
  9. {
  10. setMinimumSize(200, 200);
  11. setAcceptDrops(true);
  12. QLabel* label = new QLabel(this);
  13. label->setText("a long dummy text\na long dummy text\na long dummy text\na long dummy text\n");
  14. label->move(30, 32);
  15. label->setEnabled(true);
  16. // label->setAcceptDrops(false)
  17. }
  18.  
  19. void Table::dragEnterEvent(QDragEnterEvent* event)
  20. {
  21. qDebug() << "Table:dragEnterEvent";
  22. event->acceptProposedAction();
  23. }
  24.  
  25. void Table::dragMoveEvent(QDragMoveEvent* event)
  26. {
  27. qDebug() << "Table:dragMoveEvent";
  28. event->acceptProposedAction();
  29. }
  30.  
  31. void Table::dropEvent(QDropEvent* event)
  32. {
  33. qDebug() << "Table:dropEvent";
  34. }
To copy to clipboard, switch view to plain text mode 

I tried different combinations of label->setEnabled(true/false) and label->setAcceptDrops(true, false). I also tried to subclass QLabel and explicitly propagate dragEnterEvent, dragMoveEvent and dropEvent to QTableWidget by calling event->ignore().

Interestingly, the above code works if I replace QTableWidget by QWidget.

Any ideas of a clean Qt solution?
Qt 4.6 tested on Linux and Windows.

Thanks!