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. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dropping files from the windows explorer into a subclassed QTreeWidget

    You really don't have to touch the event handlers here. All you need is already implemented by the abstract view class -- take a look at its sources, if you don't believe us, for example:

    Qt Code:
    1. void QAbstractItemView::dragEnterEvent(QDragEnterEvent *event)
    2. {
    3. if (d_func()->canDecode(event)) {
    4. event->accept();
    5. setState(DraggingState);
    6. } else {
    7. event->ignore();
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    All things you need to reimplement are:
    bool QTreeWidget::dropMimeData ( QTreeWidgetItem * parent, int index, const QMimeData * data, Qt:ropAction action ) [virtual protected]
    Handles the data supplied by a drag and drop operation that ended with the given action in the index in the given parent item.
    See also supportedDropActions().

    QStringList QTreeWidget::mimeTypes () const [virtual protected]
    Returns a list of MIME types that can be used to describe a list of treewidget items.
    See also mimeData().

    QMimeData * QTreeWidget::mimeData ( const QList<QTreeWidgetItem *> items ) const [virtual protected]
    Returns an object that contains a serialized description of the specified items. The format used to describe the items is obtained from the mimeTypes() function.
    If the list of items is empty, 0 is returned rather than a serialized empty list.
    First method does the actual drop, second returns a list of mime-types which can be dropped onto the widget (maybe you forgot to implement it -- that's why I asked about that "stop sign" in my previous post) and the last one returns a pointer to an object describing a particular item according to mime-types returned by the previous method.

    You can take a look at equivalents of those three methods in the QAbstractItemModel class. And also remember that QTreeWidget is just a wrapper over QTreeView containing an internal model representation. For example:
    Qt Code:
    1. bool QTreeWidget::dropMimeData(QTreeWidgetItem *parent, int index,
    2. const QMimeData *data, Qt::DropAction action)
    3. {
    4. if (parent) idx = indexFromItem(parent);
    5. return model()->QAbstractItemModel::dropMimeData(data, action , index, 0, idx);
    6. }
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to wysota for this useful post:

    paltomare (15th April 2006)

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.