Results 1 to 2 of 2

Thread: dropping on headerItem

  1. #1
    Join Date
    Jan 2006
    Location
    Knivsta, Sweden
    Posts
    153
    Thanks
    30
    Thanked 13 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default dropping on headerItem

    Hi fellow hackers!

    In QT-4.1.4, I'm trying to drop something on A QTreeWidget's headerItem(), with little success.

    In the short example below, I can drag "Node 1" and "Node 2" and drop them on each other, but QT won't let me drop on the headerItem ("Node 0") even though I've set its ItemIsDropEnabled-flag. What can be done?

    Qt Code:
    1. #include <QApplication>
    2. #include <QTreeWidgetItem>
    3.  
    4. #define S(qstring) (qstring).toLatin1().constData()
    5.  
    6. class Tree : public QTreeWidget
    7. {
    8. public:
    9. Tree() : QTreeWidget() {
    10. setColumnCount(1);
    11. setDragEnabled(true);
    12. setAcceptDrops(true);
    13. }
    14. bool dropMimeData(QTreeWidgetItem *droppedOn, int, const QMimeData *, Qt::DropAction) {
    15. qDebug("Something dropped on %s", S(droppedOn->text(0)));
    16. return true;
    17. }
    18. };
    19.  
    20.  
    21. int main( int argc, char **argv )
    22. {
    23. QApplication app( argc, argv );
    24.  
    25. QTreeWidget *tree = new Tree;
    26.  
    27.  
    28. i = new QTreeWidgetItem(tree);
    29. i->setText(0, "Node 1");
    30. i->setFlags(i->flags() | Qt::ItemIsDropEnabled);
    31.  
    32. i = new QTreeWidgetItem(tree);
    33. i->setText(0, "Node 2");
    34. i->setFlags(i->flags() | Qt::ItemIsDropEnabled);
    35.  
    36. tree->headerItem()->setText(0,"Node 0");
    37. tree->headerItem()->setFlags(tree->headerItem()->flags() | Qt::ItemIsDropEnabled);
    38.  
    39. tree->show();
    40. app.exec();
    41. return 0;
    42. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: dropping on headerItem

    ItemIsDropEnabled means that you can drop some other item on this item and not that you can drop this item at all (ItemIsDragEnabled does that). I think that if you want to support dropping on headers, you have to reimplement the low level mechanisms for dropping (dragEnterEvent and family).

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.