Results 1 to 1 of 1

Thread: QTableWidget Internal Drag/ Drop Entire Row

  1. #1
    Join Date
    Jun 2012
    Posts
    219
    Thanks
    28
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget Internal Drag/ Drop Entire Row

    I've seen several posts that describe issues with internal moves overwriting the target row instead of doing something like an insert, but I have a different problem.

    I can move the row just fine as long as I drop on the first column. But, if I drop on other columns, I get varying undesirable behavior.

    Sometimes it copies the row but shifts the cells. Sometimes it does nothing (what I want). If I keep choosing cells that aren't in column 0 for the drop, an exception will be raised.

    So, I just want to prevent drops in anything other than column, or interpret a drop in any column as a drop in that row to column 0.

    I have this in the constructor of the QTableWidget:

    tableWidget->setSelectionBehavior(QAbstractItemView::SelectRow s);

    tableWidget->setDragEnabled(true);
    tableWidget->setDragDropOverwriteMode(false);
    tableWidget->setDragDropMode(QTableWidget::InternalMove);
    tableWidget->setDefaultDropAction(Qt::CopyAction);

    When I create the TableWidget, I do this (Class LineUp has a QTableWidget named tableWidget):

    void ClubRosters::add_lineup()
    {
    LineUp *newTab = new LineUp(tabWidget);
    QTableWidgetItem *cell = new QTableWidgetItem;
    for (int i=0; i<newTab->tableWidget->rowCount();i++)
    {
    for (int j=0;j<newTab->tableWidget->columnCount();j++)
    {
    cell = newTab->tableWidget->item(i,j);
    if (!cell)
    {
    cell = new QTableWidgetItem();
    if (j != 0)
    {
    cell->setFlags(cell->flags() & ~Qt::ItemIsDropEnabled);
    cell->setFlags(cell->flags() & ~Qt::ItemIsDragEnabled);
    }
    newTab->tableWidget->setItem(i,j,cell);

    }
    }
    }
    int idx = tabWidget->currentIndex ();
    bool ok = true;
    QString newName = QInputDialog::getText (
    this, tr ("Create new lineup"),
    tr ("Lineup Name"),
    QLineEdit::Normal,
    tabWidget->tabText (idx),
    &ok);

    if (ok)
    {
    tabWidget->addTab(newTab, newName);
    int count = tabWidget->count();
    tabWidget->setCurrentIndex(count-1);
    }
    }

    So, how do I prevent the drops to any columns but column 0? Or, is there a better way to implement drag/drop of entire row?

    Thanks,

    Dave Thomas


    Added after 57 minutes:


    Found this, and it does exactly what I want!

    https://bugreports.qt-project.org/br...s:all-tabpanel

    I haven't integrated into my code yet, but the example works perfectly.

    Dave Thomas
    Last edited by davethomaspilot; 16th December 2012 at 00:31.

Similar Threads

  1. Drag & Drop rows in a QTableWidget
    By vycke in forum Qt Programming
    Replies: 7
    Last Post: 19th January 2012, 00:01
  2. Replies: 1
    Last Post: 6th April 2011, 07:24
  3. Drag drop internal
    By valgaba in forum Qt Programming
    Replies: 0
    Last Post: 30th September 2010, 14:49
  4. Drag and Drop QTableWidget in UI file.
    By tpf80 in forum Qt Programming
    Replies: 3
    Last Post: 20th January 2009, 23:02
  5. Drag & Drop using QTableWidget
    By Israa in forum Qt Programming
    Replies: 21
    Last Post: 12th April 2007, 19:35

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.