Results 1 to 5 of 5

Thread: QTableView and drag & drop

  1. #1
    Join Date
    Jan 2010
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QTableView and drag & drop

    Hi, I'm new here and I have a problem that it's making me crazy.

    I'm trying to enable drag and drop between two QTableView widgets connected to a QTableModel model. No matter what I try but nothing seems to work, e.g.: holding the mouse over a row and dragging simply select other rows without dragging nothing.

    I tryed to build a minimal working example starting from tablemodel example and enabling drag in every manner I found, but I'm not able to enable dragging.

    I've read every piece of documentation I found around.

    Someone more skilled than me can explain me what I have to change in the tablemodel example to enable drag ?

    Thank you in advance.

  2. #2
    Join Date
    Jan 2010
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView and drag & drop

    Quote Originally Posted by salvaste View Post
    two QTableView widgets connected to a QTableModel model.
    ops, it's QSqlTablelModel and sql/tablemodel. sorry.

  3. #3
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QTableView and drag & drop

    you have to set the acceptDrops to true, then your dragEnter event works

    Qt Code:
    1. tableView->setAcceptDrops(true);
    To copy to clipboard, switch view to plain text mode 

    after, you have to set the action of proposed action i.e., setDropAction(...) and call the acceptProposedAction () of the QDropEvent in dragEvent handler.

    Then handle the data however you want to do in the dropEvent handler.

  4. #4
    Join Date
    Jan 2010
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView and drag & drop

    Quote Originally Posted by nikhilqt View Post
    after, you have to set the action of proposed action i.e., setDropAction(...) and call the acceptProposedAction () of the QDropEvent in dragEvent handler.

    Then handle the data however you want to do in the dropEvent handler.
    Thank you for your response. I still can not see the light ... Trying to make a summary:

    1. subclass QTableView and override dragEnterEvent and dragMoveEvent, putting there e->accept() or e->acceptProposedAction() (which one? ...)
    2. set tableView->setEnableDrags(true)
    3. set tableView->setAcceptDrops(true)
    4. anything else ?
    Last edited by salvaste; 18th January 2010 at 14:55.

  5. #5
    Join Date
    Jan 2010
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView and drag & drop

    I found out

    Quote Originally Posted by salvaste View Post
    4. anything else ?
    subclass QSqlTableModel::flags and add the flag Qt::ItemIsDragEnabled, default is to have drag disabled on the side of the model.

Similar Threads

  1. Drag Drop Tab and more
    By BingoMaster in forum Newbie
    Replies: 1
    Last Post: 26th October 2009, 06:55
  2. Drag and Drop QTableWidget and QTableView
    By scorpion11 in forum Qt Programming
    Replies: 5
    Last Post: 8th April 2008, 09:33
  3. drag and drop
    By christopher in forum Newbie
    Replies: 1
    Last Post: 19th August 2006, 20:59
  4. drag and drop
    By nupul in forum Newbie
    Replies: 9
    Last Post: 8th April 2006, 22:51
  5. Drag and Drop (drop example)
    By din9 in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2006, 18:03

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.