Results 1 to 4 of 4

Thread: Remove item from QTableView by drag

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Remove item from QTableView by drag

    Hi commuity,

    I would like to achieve this behavior:

    I select some items in my QTableView widget, keeping the left button pressed, I drag the items outside the view -> the items are deleted from the model.

    Something similar to drag&drop but with the result that the items are removed instead of dropped onto another widget.

    Sincerely
    Franco Amato

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Remove item from QTableView by drag

    Sounds like a good way to get your users angry at you. Will this action come with an Undo feature? If not, what happens if the user grabs and drags the wrong item? How does she get it back?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Remove item from QTableView by drag

    It does not come with an Undo feature
    Franco Amato

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Remove item from QTableView by drag

    It does not come with an Undo feature
    I think you will be sorry for that. It will be the first thing on the bug report list.

    To implement this, I think you will need to set QAbstractItemView::setDragEnabled() to true when there are selected items and the left mouse button has been pressed but not released, and QAbstractItemView::setDragDropMode() to DragOnly. You will also need to return the QAbstractItemModel::flags() with the value Qt::ItemIsDragEnabled set. You probably also have to watch for a QDragLeaveEvent and then watch at the application level for a QDropEvent. I don't know what happens if the user drags the items out of the application entirely.

    This will be even more complicated if you already have drag and drop enabled so the user can rearrange items in the view.

    Frankly, this sounds like a whole lot of work for something that is really just a piece of UI fluff. You could easily accomplish the same thing simply by letting the user select items from the table and then pressing the delete key. And that would give you the opportunity to ask "Are you sure?" before the items are actually deleted.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. The following user says thank you to d_stranz for this useful post:

    franco.amato (15th March 2022)

Similar Threads

  1. Replies: 2
    Last Post: 30th January 2014, 07:46
  2. QTableView Drag to change item order not working
    By Marlon Smith in forum Qt Programming
    Replies: 0
    Last Post: 29th August 2012, 20:44
  3. Remove an item
    By giusepped in forum Qwt
    Replies: 1
    Last Post: 16th September 2009, 08:47
  4. QListWidgetItem remove an item
    By mattia in forum Newbie
    Replies: 4
    Last Post: 9th November 2007, 08:57
  5. remove item from QListWidget
    By yushinee in forum Newbie
    Replies: 3
    Last Post: 2nd October 2007, 21:40

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.