Results 1 to 8 of 8

Thread: Drag & Drop rows in a QTableWidget

  1. #1
    Join Date
    Dec 2007
    Location
    Austin, TX
    Posts
    43
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Drag & Drop rows in a QTableWidget

    Here's another one for you guys to point me to where I messed up

    I'm trying to get DnD to work on rows of a QTableWidget. I've gotten it to Drag & Drop the row (by turning off dragenable & dropenable except on the first column -- which probably isn't very user friendly, but keeps it from shifting all the bloody data)... but even with setDragDropOverwriteMode(false), the data in the drop target is overwritten (instead of having the moved row inserted, like the docs say).

    I suspect I'll have to derive from the QTableWidget to get the data not allowed to drop off the table (i.e. it'd vanish) -- but do I need to derive to get the row move properly?

    I'll post code if needed, but it's really just the QTableWidgetItem creations & the table & settings are from designer (and, yes, I tried to put the Overwrite Mode thing in my code... but no difference between true or false).

    Thanks,
    Vycke

  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: Drag & Drop rows in a QTableWidget

    First of all try dropping between rows instead of dropping on a row. If you have the drop indicator activated, it should be displayed as a line between rows instead of a frame around a cell of the table. You can make sure you can't drop on a cell (instead of between cells) by removing the ItemIsDropEnabled flag.

  3. #3
    Join Date
    Dec 2007
    Location
    Austin, TX
    Posts
    43
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drag & Drop rows in a QTableWidget

    I've tried the following:
    Qt Code:
    1. table->setDragDropOverwriteMode(false);
    2. table->setDragEnabled(true);
    3. table->setDragDropMode(QAbstractItemView::InternalMove);
    To copy to clipboard, switch view to plain text mode 

    With the items:
    Qt Code:
    1. item->setFlags(item->flags() & ~(Qt::ItemIsDropEnabled));
    To copy to clipboard, switch view to plain text mode 

    But I can't get it to drop on the line (unless that's the '+' indicator)... and the cell under/near the drop is still overwritten. Using 4.3.2, if that makes any difference (bug?).

  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: Drag & Drop rows in a QTableWidget

    Could you prepare a minimal compilable example reproducing the problem?

  5. #5
    Join Date
    May 2010
    Posts
    23
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drag & Drop rows in a QTableWidget

    It appears you have to use model/view stuff for such a basic thing. And that sucks.

  6. #6
    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: Drag & Drop rows in a QTableWidget

    What kind of "basic thing"?
    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
    May 2010
    Posts
    23
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drag & Drop rows in a QTableWidget

    Draging the table row with a mouse to a new place in the same table without deleting previous content.

  8. #8
    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: Drag & Drop rows in a QTableWidget

    No, you can do that with QTableWidget as well. That's what InternalMove does by default, anyway. Unless you mean you want to copy the item, then internal move, as the name suggests, does something different.
    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. Drag and Drop QTableWidget and QTableView
    By scorpion11 in forum Qt Programming
    Replies: 5
    Last Post: 8th April 2008, 10:33
  2. Drag & Drop using QTableWidget
    By Israa in forum Qt Programming
    Replies: 21
    Last Post: 12th April 2007, 20:35
  3. Replies: 7
    Last Post: 8th September 2006, 17:19
  4. Drag and drop revisited
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 30th June 2006, 17:41
  5. Replies: 6
    Last Post: 5th March 2006, 22:05

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.