Unsolved select multiple items(dragable and non-dragable) causing the non-dragable items to disappear
-
I have two QListWidget. Some items within are dragable, some are non-dragable. The non-dragable items are non-selectable and non-enabled. However when I select multiple items(dragable and non-dragable) using the mouse( the list is set to selection mode: ExtendedSelection), the non-dragable items disappear totally. Is this a bug??
-
The non-dragable items are non-selectable
when I select multiple items(dragable and non-dragable)
How do you select non-selectable items?
-
@VRonin Yes the non-selectable canont be selected upon mouse clicks. But if you just drag your mouse across multiple items to perform a multi-select, somehow after the drag and drop to another list, the non-selectable items disappears.
-
disappear from the original list or from the data of the drag/drop event?
-
@VRonin non-dragable items disappear from the original source list, while dragable items move to the destination list.
-
This is very strange. Can you post a minimum example so we can have a deeper look into it?
-
@Darren Hi
I admit I didn't read the article for absence of time, I'm sorry, but I found this link:I hope it help you
-
@CP71 Thank you Cp71. I read this link previously but do not understand what they mean by creating QMimeData and QDrag objects in your source list widget's mouseMoveEvent.
Secondly, is this a valid bug in QT? why aren't they solve this bug? -
@Darren Hi,
Sorry but I don’t understand, don’t worry, depend of my English isn’t good ;), if you didn't fix your problem or if fixed and are requiring further information (but I think you fixed your issue).The fix is the flag you pass at setDefaultDropAction function, Qt::MoveAction moves the items, Qt::CopyAction copies the items.
I quickly read the article. About the QMineData and QDrag (if I don’t mistake, objects for data transfer via clipboard and drag and drop) mentioned in the article, I did not investigate in depth but I suppose writer says you that Qt manages them and you mustn't delete them.
For me this isn’t a bug of Qt.
Anyway I quickly created a simple example that is based on example in the link, I tried it and works well:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); ui->listWidget->setDragDropMode(QAbstractItemView::DragDrop); // ui->listWidget->setDefaultDropAction(Qt::MoveAction); ui->listWidget->setDefaultDropAction(Qt::CopyAction); ui->listWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); ui->listWidget_2->setDragDropMode(QAbstractItemView::DragDrop); // ui->listWidget_2->setDefaultDropAction(Qt::MoveAction); ui->listWidget_2->setDefaultDropAction(Qt::CopyAction); ui->listWidget_2->setSelectionMode(QAbstractItemView::ExtendedSelection); fillListWidget(ui->listWidget, 8, "someItem"); fillListWidget(ui->listWidget_2, 4, "anotherItem"); } void MainWindow::fillListWidget(QListWidget *listWidget, int numItems, QString txt) { QString newTxt; for ( int i=0; i< numItems; i++ ) { QListWidgetItem *item = new QListWidgetItem(); newTxt = QString("%1_%2").arg(txt).arg(i); if ( i % 2 ) { item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); } else { // If the item is draggable, indicate it with a * newTxt += ' *'; item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled ); } item->setText(newTxt); listWidget->addItem(item); } }
-
@CP71 My application needs a MOVE action. Not a COPY action. If you try
ui->listWidget_2->setDefaultDropAction(Qt::MoveAction)
this will cause the non-dragable items to be DELETED. -
@Darren Hi
Ok, now I understand your problem.
Sorry. -
Please provide a simple, compilable example so we can take a deeper look on your problem.
-
Hi
Using @CP71 (thanks :) code as base it was fast to make sample.
It does seems it does not honor movable if multiple is selected
and after the drop ( which only shows the correct ones) , it seems to delete/remove
all of selection even some were not dropped. ( those without *)Read to run project
https://www.dropbox.com/s/urt1pwfvqs3xmbj/DragDropFail.zip?dl=0(tested on win 10, Qt5.12)
-
@mrjj : Thx for the reproducer. will take a look on soon.
Since there is no bugreport about this (at least I'm not aware of one) - can someone please create them :) -
Here a first shot: https://codereview.qt-project.org/251888
As a workaround you can override QAbstractItemView::startDrag() and adjust the selected items to only contain the ones which are also dragable. -
Hi
Damn, you are fast :)
Do we still need a bug report ? -
@mrjj It would be nice to have a bug report to get an official bug so it can be better documented later on. I also need to create another testcase for QTreeView and esp. for QListView in icon mode since there is a special handling.
-
@Christian-Ehrlicher
https://bugreports.qt.io/browse/QTBUG-73465
Please let me know if i need to change something.