Results 1 to 5 of 5

Thread: Dragging out of a QTreeView with a ProxyModel

  1. #1
    Join Date
    Jun 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Dragging out of a QTreeView with a ProxyModel

    I'm trying to get dragging to work using a QTreeView and a custom ProxyModel that contains a QSqlQueryModel. I'm using the ProxyModel to do grouping based on the values of some column of the data.
    Now I want the user to be able to drag leafs of the tree out of the tree to another widget in my app.

    I read http://doc.qt.nokia.com/4.7/model-vi...ith-item-views and did everything stated there, but dragging (and dropping for that matter) doesn't work in the least: the drag is never started, startDrag() is never called (placed a breakpoint in QAbstractItemView code). The only thing that happens is that the item is selected.
    What could I be doing wrong?
    I don't need to subclass QTreeView since it should be able to handle it out-of-the-box, right?
    The QTreeView is inside a QDockWidget, if that matters.

    The drag and drop examples work, but they don't use a View, just plain Widgets.


    Added after 50 minutes:


    If I set the selectionBehaviour to SelectItems, it works...
    Can it have something to do with the fact that I remove columns in my proxymodel, so that SelectRows has trouble selecting the entire row somehow?
    Should I override mapSelectionFromSource/mapSelectionToSource to make it work on rows perhaps?
    Last edited by jmichiel; 17th June 2011 at 21:37.

  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: Dragging out of a QTreeView with a ProxyModel

    How did you implement flags() for your model? What is the value of the dragEnabled property for the view? How did you implement mimeData() for the model?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Dragging out of a QTreeView with a ProxyModel

    dragEnabled is true, and these are the flags and mimeData methods (pretty much as in the documentation:
    Qt Code:
    1. Qt::ItemFlags ThemaLesModel::flags(const QModelIndex &index) const
    2. {
    3. Qt::ItemFlags defaultFlags = sourceModel()->flags(mapToSource(index));
    4. if (index.isValid())
    5. return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
    6. return defaultFlags;
    7. }
    8.  
    9.  
    10. QMimeData *ThemaLesModel::mimeData(const QModelIndexList &indexes) const
    11. {
    12. QMimeData *mimeData = new QMimeData();
    13. QByteArray encodedData;
    14.  
    15. QDataStream stream(&encodedData, QIODevice::WriteOnly);
    16.  
    17. foreach (const QModelIndex &index, indexes) {
    18. if (index.isValid()) {
    19. QString text = data(index, Qt::DisplayRole).toString();
    20. stream << text;
    21. }
    22. }
    23.  
    24. mimeData->setData("application/vnd.text.list", encodedData);
    25. return mimeData;
    26. }
    To copy to clipboard, switch view to plain text mode 

    If I use 'SelectRows', than I can't do anything. Using SelectItems, it works, but only for the original data rows, not for the 'virtual' ones I introduced myself for the grouping. While debugging, I saw that apparently it's the selectionModel that tells the view there are no selections when in SelectRows mode.

  4. #4
    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: Dragging out of a QTreeView with a ProxyModel

    Is ThemaLesModel the proxy or the base model?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jun 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Dragging out of a QTreeView with a ProxyModel

    ThemaLesModel is derived from the Grouping proxy. The sourceModel is a QSqlQueryModel

Similar Threads

  1. Replies: 0
    Last Post: 5th April 2011, 12:40
  2. ProxyModel problem
    By waynew in forum Qt Programming
    Replies: 1
    Last Post: 14th February 2010, 06:40
  3. Sharing Selections between Model and ProxyModel
    By mentat in forum Qt Programming
    Replies: 14
    Last Post: 27th January 2010, 17:31
  4. ProxyModel and ItemDelegate work togather?
    By litterflybug in forum Qt Programming
    Replies: 0
    Last Post: 15th December 2009, 02:28
  5. Replies: 2
    Last Post: 6th January 2009, 20:55

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.