Results 1 to 2 of 2

Thread: List Widget drag drop items

  1. #1
    Join Date
    Jan 2014
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Question List Widget drag drop items

    Hi everyone!

    I'm trying to implement the List Widget's drag and drop feature. It almost works, but every time I drop an item on a new position it moves but the list scrolls to the top and the item I move doesn't get selected.

    What I did is just added a List Widget as a centralWidget using the designer. It's name is as simple as "listWidget", and I set it's properties as follows:

    DragDropMode - internalMove;
    selectionMode - extendedSelection;
    movement - snap;

    Then i just populate it with some items in my mainwindow.cpp as follows:
    Qt Code:
    1. for(int i = 0; i < 51; i++)
    2. {
    3. new QListWidgetItem("Item " + QString::number(i), ui->listWidget);
    4. }
    To copy to clipboard, switch view to plain text mode 
    That's it. So why the whole list scrolls to the top and the moved item doesn't stay selected?

    Timely thanks for your help guys!

  2. #2
    Join Date
    Jan 2014
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Question List Widget and List View drag and drop issue (it scrolls to top)

    Hi everyone!

    I'm trying to implement the List Widget's drag and drop feature. It almost works, but every time I drop an item on a new position it moves but the list scrolls to the top and the item I move doesn't get selected.

    What I did is just added a List Widget as a centralWidget using the designer. It's name is as simple as "listWidget", and I set it's properties as follows:

    DragDropMode - internalMove;
    selectionMode - extendedSelection;
    movement - snap;

    Then i just populate it with some items in my mainwindow.cpp as follows:
    Qt Code:
    1. for(int i = 0; i < 51; i++)
    2. {
    3. new QListWidgetItem("Item " + QString::number(i), ui->listWidget);
    4. }
    To copy to clipboard, switch view to plain text mode 

    The same happens with List View event if I reimplement and give it my own model with such reimplemented methods as:
    Qt Code:
    1. Qt::DropActions supportedDropActions() const
    2. {
    3. return Qt::CopyAction | Qt::MoveAction;
    4. }
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. Qt::ItemFlags flags(const QModelIndex &index) const
    2. {
    3. if (index.isValid())
    4. {
    5. return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
    6. }
    7. else
    8. {
    9. return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 


    That's it. So why the whole list scrolls to the top and the moved item doesn't stay selected?

    Timely thanks for your help guys!

Similar Threads

  1. Drag and drop from list/tree widget to graphics view
    By chaltier in forum Qt Programming
    Replies: 1
    Last Post: 25th March 2012, 05:15
  2. drag and drop in list widgets
    By GrahamLabdon in forum Newbie
    Replies: 1
    Last Post: 28th May 2011, 09:51
  3. Replies: 1
    Last Post: 6th April 2011, 08:24
  4. Replies: 1
    Last Post: 22nd December 2010, 16:17
  5. Drag and Drop from a list to a form
    By orbital_fox in forum Qt Programming
    Replies: 0
    Last Post: 1st October 2009, 19:29

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.