Results 1 to 3 of 3

Thread: Dropping on QTableWidget's child

  1. #1
    Join Date
    Jun 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Dropping on QTableWidget's child

    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!

  2. #2
    Join Date
    Jun 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Dropping on QTableWidget's child

    Nobody has an idea? Can this be a bug by Qt?

  3. #3
    Join Date
    Jun 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Dropping on QTableWidget's child

    I use an workaround now: I've subclassed QLabel and implemented the same drag'drop functionality for the Label. Since this contains a lot of redundant code I would still be glad if someone could tell me if I'm doing something wrong or if this is a bug by Qt!

Similar Threads

  1. problem while dropping into QTableView
    By jay in forum Qt Programming
    Replies: 3
    Last Post: 12th September 2008, 19:22
  2. drag/dropping outside app
    By musikit in forum Qt Programming
    Replies: 4
    Last Post: 29th February 2008, 18:34
  3. Dropping into QListView
    By akiross in forum Newbie
    Replies: 2
    Last Post: 24th February 2008, 22:10
  4. Dropping onto a QSqlQueryModel
    By kroenecker in forum Qt Programming
    Replies: 14
    Last Post: 16th November 2006, 20:20
  5. dropping on headerItem
    By drhex in forum Qt Programming
    Replies: 1
    Last Post: 4th July 2006, 10:33

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.