Results 1 to 2 of 2

Thread: QTableView drag-n-drop to change order, an empty row remains

  1. #1
    Join Date
    Mar 2014
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question QTableView drag-n-drop to change order, an empty row remains

    Dear all,

    I use a QTableView to display products information described with QStandardItemModel. I need to implement the feature to change row order via drag-and-drop. Here is the code:
    .h file:
    QTableView *tableView_allProducts.
    QStandardItemModel *ensembleProductModel;

    .cpp file:
    ensembleProductModel = new QStandardItemModel(0, PRODUCT_COLUMN_COUNT);
    tableView_allProducts->setModel(ensembleProductModel);
    tableView_allProducts->setSelectionMode(QAbstractItemView::ExtendedSelec tion);
    // When user select an item, the whole row is selected
    tableView_allProducts->setSelectionBehavior(QAbstractItemView::SelectRow s);
    // Implement the feature to change row order via drag-n-drop
    tableView_allProducts->setDragEnabled(true);
    tableView_allProducts->setDragDropMode(QAbstractItemView::InternalMove );
    tableView_allProducts->setDropIndicatorShown(true);

    The problem with the above code is that after the selected row is moved to the new position, an empty row with default values (zeros) remains at the original position. So there is one more row after drag-n-drop. What’s problem with my code? Thanks.

    My development tools are Visual Studio 2008, Qt 4.8.3.

  2. #2
    Join Date
    Jun 2014
    Posts
    98
    Thanks
    43
    Thanked 4 Times in 4 Posts
    Platforms
    Windows

    Default Re: QTableView drag-n-drop to change order, an empty row remains

    I had this (and other) problems with QTableWidget. Got some help with it here:
    http://stackoverflow.com/questions/2...n-qtablewidget

Similar Threads

  1. QListView remains empty
    By postb99 in forum Newbie
    Replies: 1
    Last Post: 13th February 2014, 20:34
  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. Replies: 2
    Last Post: 13th October 2010, 22:51
  4. How to change the order of QTableView Column ?
    By Kode.Cooper in forum Qt Programming
    Replies: 1
    Last Post: 27th January 2010, 09:55
  5. Drag and drop items in view to sort order
    By Big Duck in forum Qt Programming
    Replies: 1
    Last Post: 25th May 2006, 20:43

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.