Results 1 to 8 of 8

Thread: Changing row order by dragging them

  1. #1
    Join Date
    Jun 2009
    Posts
    21
    Qt products
    Platforms
    Unix/X11 Windows

    Default Changing row order by dragging them

    I want to change row order in my custom model by dragging them. I've table view and custom model using QAbstractTableModel. I need the same behaviour as in listWidget , when I can reorder items by dragging them. What I need to do to achieve the same effect in model/view ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Changing row order by dragging them

    You need to teach your model to do that by implementing QAbstractItemModel::mimeData() and QAbstractItemModel::dropMimeData().
    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 2009
    Posts
    21
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: Changing row order by dragging them

    I'm having problem with mimeData and dropMimeData implementation. If I implement both of them only mimeData method is working. When I implement only one of them they're correctly invoked. What should I do to have both methods working correctly ?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Changing row order by dragging them

    How did you reimplement them?
    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 2009
    Posts
    21
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: Changing row order by dragging them

    I reimplemented them in the most basic form in order to check if they're working:

    Qt Code:
    1. def dropMimeData(self, data, action, row, column, parentIndex):
    2. print 'drop'
    3. return True
    4.  
    5. def mimeData(self, indexes):
    6. print 'drag'
    7. mime = QtCore.QMimeData()
    8. return mime
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Changing row order by dragging them

    Essentially your mimeData implementations says "I do not accept any drops" so dropMimeData will never be called.
    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.


  7. #7
    Join Date
    Jun 2009
    Posts
    21
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: Changing row order by dragging them

    How should I enable drop in mimeData method ? According to Qt reference mimeData contains data corresponding to indexes, so what I need to do to enable drop in this method ? I was thinking that mimeData method only returns mimeData object based on indexes. If there is any example that shows how to do this ?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Changing row order by dragging them

    Did you reimplement mimeTypes() as well? I confused the two methods a bit. Your mimeData() actually says "I don't have anything interesting to drag" and not "I don't accept drops". That's what mimeTypes() returns. Read the docs for all three methods, you'll need them all.
    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.


Similar Threads

  1. Replies: 2
    Last Post: 28th October 2016, 12:12
  2. Changing QTableView column display order
    By scarleton in forum Qt Programming
    Replies: 3
    Last Post: 18th October 2010, 01:04
  3. Replies: 5
    Last Post: 25th February 2010, 18:29
  4. Changing column order in QTableView
    By Banjo in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2008, 07:49
  5. Changing the order of columns in QTreeView
    By johnny_sparx in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2006, 01:00

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.