Results 1 to 2 of 2

Thread: QTreeView and d&d

  1. #1
    Join Date
    Sep 2011
    Posts
    8
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default QTreeView and d&d

    Hello

    Im facing a little problem regarding QTreeView and drag&drop.

    I want to restrict drop only in between the items. I found a good working suggestion on forum so this was not a big deal.

    The problem is that i want to restrict items being dropped into different columns, lets say i have file, size and date column and i dont want the file item end up in the date or size column.

    right now im using this inherited model class based on the suggestion i mentioned before.

    Qt Code:
    1. class Model : public QStandardItemModel
    2. {
    3. public:
    4. Model(int rows, int cols, QObject* parent = 0) : QStandardItemModel(rows, cols, parent)
    5. {
    6. }
    7.  
    8. Qt::ItemFlags flags(const QModelIndex& inIndex) const
    9. {
    10.  
    11. if(!inIndex.isValid() )
    12. return Qt::ItemIsDropEnabled;
    13.  
    14.  
    15. return Qt::ItemIsDragEnabled | Qt::ItemIsSelectable | Qt::ItemIsEnabled ;
    16. }
    17. };
    To copy to clipboard, switch view to plain text mode 

    Is there a way to do this without completely new customized QTreeView?

    Or maybe is there better component for this particular purpose than QTreeView?



    thanks a lot!

  2. #2
    Join Date
    Sep 2011
    Posts
    8
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: QTreeView and d&d

    Ok i sorted it out and in case someone is facing the same problem.

    i used the code in previous post for the model of treeview and made a sub-class of QTreeView with this dropEvent:

    Qt Code:
    1. void CTreeView::dropEvent(QDropEvent *event)
    2. {
    3. if(event->pos().x() > this->columnWidth(0))
    4. event->setPoint(QPoint(this->columnWidth(0)/2,event->pos().y()));
    5.  
    6. QTreeView::dropEvent(event);
    7. }
    To copy to clipboard, switch view to plain text mode 

    this is restriction to first column and any attempst to drop into other columns will be sent back to first column

    I hope this helps to someone

Similar Threads

  1. Help ...QTreeView
    By Raymond in forum Qt Programming
    Replies: 2
    Last Post: 16th September 2009, 09:18
  2. QTreeView
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 4th March 2009, 19:51
  3. use QTreeView
    By totosugito in forum Qt Programming
    Replies: 2
    Last Post: 30th January 2008, 09:33
  4. QTreeView
    By merry in forum Qt Programming
    Replies: 5
    Last Post: 29th May 2007, 08:38
  5. QTreeView
    By npc in forum Qt Programming
    Replies: 2
    Last Post: 24th January 2007, 07:53

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.