Results 1 to 8 of 8

Thread: Dropping files from the windows explorer into a subclassed QTreeWidget

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2006
    Posts
    5
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question Dropping files from the windows explorer into a subclassed QTreeWidget

    Hi
    I try to implement to drop files from the windows explorer to a QTreeWidget (this one is subclassed clsMyTree (I need such feature to open the files and extract data to fill the tree).
    The problem that I have is that couldn't found any way to accept the QTreeWidget to see the drop object.
    See some test class below:
    Qt Code:
    1. ///////////////////start class //////////////////////////
    2. ///////////header file//////
    3. #include <QtGui/QApplication>
    4. #include <QtGui/QTreeWidget>
    5. class clsMyTree :
    6. public QTreeWidget
    7. {
    8. Q_OBJECT
    9. public:
    10. clsMyTree(void);
    11. clsMyTree( QWidget *p=0); //: QTreeWidget(p) { }
    12. virtual ~clsMyTree(void);
    13. protected:
    14. virtual bool event(QEvent *event);
    15. virtual bool dropMimeData ( QTreeWidgetItem * parent, int index, const QMimeData * data, Qt::DropAction action );
    16. public slots:
    17. void setValue();
    18.  
    19. signals:
    20. void valueChanged(int newValue);
    21. };
    22.  
    23. ///////////cpp file//////
    24. #include "heaMyTree.h"
    25. #include <QDropEvent>
    26. clsMyTree::clsMyTree(void)
    27. {
    28. }
    29. clsMyTree::clsMyTree( QWidget *p) : QTreeWidget(p) {
    30. setAcceptDrops(true);
    31. p->setAcceptDrops(true);
    32. }
    33.  
    34. clsMyTree::~clsMyTree(void)
    35. {
    36. }
    37.  
    38. bool clsMyTree::dropMimeData ( QTreeWidgetItem * parent, int index, const QMimeData * data, Qt::DropAction action ){
    39. parent=parent;
    40. return true;
    41. }
    42.  
    43. bool clsMyTree::event(QEvent *event)
    44. {
    45. if (event->type() == QEvent::Drop) {
    46. QDropEvent *pEv=static_cast<QDropEvent *>(event);
    47. Qt::DropAction dropAct=pEv->dropAction ();
    48. long lActio=0;
    49. lActio=dropAct;
    50. }
    51.  
    52. return QWidget::event(event);
    53. }
    54.  
    55.  
    56. void clsMyTree::setValue()
    57. {
    58.  
    59. }
    60. ///////////////////end class //////////////////////////
    To copy to clipboard, switch view to plain text mode 
    With this example I catch one file from the windows explorer and try to drop it into the clsMyTree(inherited from QTreeWidget) and no event happen in my reimplemented functions ::event,dropMimeData and so on. Nor he display me the right mousecursor.
    For me it looks like the widget are not right enabled for dropping objects that are
    incomming out from another application. In this case windows explorer.
    I there somebody that have experience with such kind of works?
    Is the QTreeWidget the right widget for such things and is my implementation right or maybe I forgote something others?

    PS: The example was done with QT 4.1 and Visual Studio 2003. For the main
    widget I use also the designer. But unfortunately the new designer is for
    such works, especially for this drag and drop problem, not really
    helpfully.
    In the mean time I try to do this with KDevelop and KDE in Linux.
    I would really appreciate any helps.

    Thanks

    Piero
    Last edited by wysota; 14th April 2006 at 12:49. Reason: Missing [code] tags

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
  •  
Qt is a trademark of The Qt Company.