Results 1 to 3 of 3

Thread: QTableView move internal is very confusing

  1. #1
    Join Date
    Nov 2016
    Posts
    2
    Qt products
    Platforms
    Unix/X11

    Default Re: QTableView move internal is very confusing

    I'm using PyQT4 and have an application with the GUI designed in QT Designer. In my application I have a custom dialog with a simple QTableView with a custom model extended from QAbstractTableModel. It works fine, but now I'm trying to implement internal move of rows, i.e. drag and drop a single row to a new position. I have tried every combination of drag and drop options in QAbstractItemView (in QT Designer), currently I'm using these settings:

    dragEnabled: True
    dragDropOverwrite: False
    dragDropMode: InternalMove
    defaultDropAction: MoveAction
    selectionMode: SingleSelection
    selectionBehaviour: SelectRows

    Then in my model I have implemented the following functions:

    rowCount()
    columnCount()
    headerData()
    data()
    setData()
    flags()
    supportedDragActions()
    supportedDropActions()
    addRow()
    insertRows()
    removeRow()
    removeRows()

    The flags I return are the following:
    Qt.ItemIsDragEnabled | Qt.ItemIsDropEnabled | Qt.ItemIsEditable | Qt.ItemIsEnabled | Qt.ItemIsSelectable

    And supportedDragActions/supportedDropActions return:
    Qt.CopyAction | Qt.MoveAction

    When I test I can see that if I drag a row and drop it exactly between two rows, the row I dragged gets deleted (removeRows() is called) and insertRows() is also called as it should. But if I drop at another row, only removeRows() is called. I guess this is because in the first case the table handle the drop, in the second case, the item handles the drop. But I'm not sure how to solve it...


    Added after 39 minutes:


    One detail I can not figure out is if I really need to implement dropMimeData() and mimeData() or if it is only if I want to allow external drag and drop...
    Last edited by UglyBob; 9th November 2016 at 13:50.

  2. #2
    Join Date
    Nov 2016
    Posts
    2
    Qt products
    Platforms
    Unix/X11

    Default Re: QTableView move internal is very confusing

    No one has a working code example of a QTableView/model that supports internal move?

  3. #3
    Join Date
    Mar 2014
    Posts
    23
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: QTableView move internal is very confusing

    Quote Originally Posted by UglyBob View Post
    One detail I can not figure out is if I really need to implement dropMimeData() and mimeData() or if it is only if I want to allow external drag and drop...
    You don't need to implement those for purely internal drag'n'drop operations.

    Unfortunately I don't know any solution to that other issue. I literally did the same as you but with a QListView. Dropping any item in between two others works but it gets "swallowed" when being dropped onto another item. Couldn't find out how to avoid this or what would be the right way to accomplish this.

    So I would also be highly interested in any kind of solution.

Similar Threads

  1. QTableView how to move columns with code
    By Marco in forum Qt Programming
    Replies: 5
    Last Post: 28th March 2016, 13:00
  2. Replies: 0
    Last Post: 21st January 2016, 04:40
  3. qtableview signal to model for internal drag and drop?
    By RolandHughes in forum Qt Programming
    Replies: 3
    Last Post: 16th November 2014, 13:14
  4. How to move QPixmap in QTableView
    By Borland in forum Qt Programming
    Replies: 2
    Last Post: 1st March 2012, 09:38

Tags for this Thread

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.