Results 1 to 7 of 7

Thread: Drag and Drop on Whitespace of QTreeView

  1. #1
    Join Date
    May 2008
    Posts
    15
    Thanks
    1

    Default Drag and Drop on Whitespace of QTreeView

    Hi everybody,

    I read the Drag and Drop with Item views tutorial but somehow, drag drop is only working when im droping on an existing item within the treeview.

    How do I drop items on the empty area within a treeview?

    thx in advance,
    Mike

  2. #2
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default Re: Drag and Drop on Whitespace of QTreeView

    take a look at the function where the dropaction is accepted. Their must be something e.g. that makes the invisible parent item rejecting drops (or something similar).

  3. #3
    Join Date
    May 2008
    Posts
    15
    Thanks
    1

    Default Re: Drag and Drop on Whitespace of QTreeView

    hmm it looks like this:

    Qt:ropActions CLTLectionModel::supportedDropActions() const
    {
    return Qt::CopyAction | Qt::MoveAction;
    }

  4. #4
    Join Date
    May 2008
    Posts
    15
    Thanks
    1

    Default Re: Drag and Drop on Whitespace of QTreeView

    how do i drop on the top level of my treeview? do i have to edit my custom model?

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Drag and Drop on Whitespace of QTreeView

    Reimplement QAbstractItemModel::flags() to return Qt::ItemIsDropEnabled (together with other flags) for invalid indexes.
    J-P Nurmi

  6. #6
    Join Date
    May 2008
    Posts
    15
    Thanks
    1

    Default Re: Drag and Drop on Whitespace of QTreeView

    Hi jpn,

    my flags already contain such flags. Do you have any other idea?



    Qt Code:
    1. Qt::ItemFlags CLTLectionModel::flags(const QModelIndex &index) const
    2. {
    3. if (!index.isValid())
    4. return Qt::ItemIsEnabled;
    5.  
    6. return QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
    7. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 14th May 2008 at 13:30. Reason: missing [code] tags

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Drag and Drop on Whitespace of QTreeView

    I think Qt::ItemIsEnabled for invalid items is pointless. Also, you are not returning Qt::ItemIsDropEnabled for invalid items..
    J-P Nurmi

  8. The following user says thank you to jpn for this useful post:

    T1c4L (14th May 2008)

Similar Threads

  1. Drag & drop items on the same QTreeView
    By wind in forum Qt Programming
    Replies: 2
    Last Post: 11th October 2006, 14:29
  2. Replies: 7
    Last Post: 8th September 2006, 16:19
  3. Drag and drop revisited
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 30th June 2006, 16:41
  4. drag and drop from QTreeView
    By Untersander in forum Qt Programming
    Replies: 1
    Last Post: 10th April 2006, 09:00
  5. Drag & drop for QTreeView
    By yogeshm02 in forum Qt Programming
    Replies: 2
    Last Post: 30th January 2006, 14:32

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.