QListWidget drag/drop documentation/behaviour
-
@JonB said in QListWidget drag/drop documentation/behaviour:
I invite you to place the following line above your two lines:
The only thing how I could explain it, is that as I've assumed before, the different "modes" are handled independently.
Default mode is notIconMode
. So maybe all the settings you make, only apply for the current mode (intentionally or not?!) and when you switch theviewMode
everything resets / defaults, so you can drop the stuff again... oof... :)QtDesigner at it's best :P
@Pl45m4
As I showed in the code from your woboq file, it's kind of like that, but not completely. SettingIconMode
causes a couple of changes to be made. The trouble is, where they put that line in theui....h
file from Designer properties "undoes" some of the other proprieties you have also set there. Without you realising.Anyway, I'm good to go now that I know why & what, just "bruised" from the length of the tussle... ;-)
-
@Pl45m4
As I showed in the code from your woboq file, it's kind of like that, but not completely. SettingIconMode
causes a couple of changes to be made. The trouble is, where they put that line in theui....h
file from Designer properties "undoes" some of the other proprieties you have also set there. Without you realising.Anyway, I'm good to go now that I know why & what, just "bruised" from the length of the tussle... ;-)
@JonB said in QListWidget drag/drop documentation/behaviour:
The trouble is, where they put that line in the ui....h file from Designer properties "undoes" some of the other proprieties you have also set there.
Yes... so it's impossible to get that behavior you asked for, when using QtDesigner even tho it is theoretically possible because these are just 3 properties. Just a matter of order. If
uic
will always put it this way... it doesn't work and you don't know why :)Another reason to use QtD for placing widgets and other stuff only and do the rest with code :)
-
@VRonin said in QListWidget drag/drop documentation/behaviour:
listWid->setDragEnabled(true); listWid->setDragDropMode(QAbstractItemView::DragOnly);
Dear @VRonin,
I hope you might take a couple of minutes to look at this --- just OOI and to feel my pain --- since I have spent so much time trying to figure why your sample code does work but that generated from Designer does not.
I invite you to place the following line above your two lines:
listWid->setViewMode(QListView::IconMode);
(The only thing I care about is that you can still start a drag, and you cannot drop the drag back in the list widget to cause changed layout.) Everything still works, right?
Now please move that line to after the original two lines. This is where it ends up from the
.ui
file/uic
generator toui_....h
from setting all these properties. Now try.... You can now drag & drop the items around the list widget to re-arrange them, can't you? Which is what I was wanting to prevent.Now that I have figured this I am of course OK going forward. But I should like sympathy for how long it has taken to me to determine what has been going on... ;-)
@JonB said in QListWidget drag/drop documentation/behaviour:
Now please move that line to after the original two lines. This is where it ends up from the .ui file/uic generator to ui_....h from setting all these properties. Now try.... You can now drag & drop the items around the list widget to re-arrange them, can't you? Which is what I was wanting to prevent.
Indeed, this is due to
QListView::setViewMode
overwriting theacceptDrops
property (see https://code.woboq.org/qt5/qtbase/src/widgets/itemviews/qlistview.cpp.html#_ZN9QListView11setViewModeENS_8ViewModeE). It's been like this since before the Nokia days so I can't easily dig out why this is the case.For people ending up here from a search engine, the solution is to put
ui->listWidget->setDragDropMode(QAbstractItemView::DragOnly);
in your widget constructor after the call tosetupUi()
-
@JonB said in QListWidget drag/drop documentation/behaviour:
Now please move that line to after the original two lines. This is where it ends up from the .ui file/uic generator to ui_....h from setting all these properties. Now try.... You can now drag & drop the items around the list widget to re-arrange them, can't you? Which is what I was wanting to prevent.
Indeed, this is due to
QListView::setViewMode
overwriting theacceptDrops
property (see https://code.woboq.org/qt5/qtbase/src/widgets/itemviews/qlistview.cpp.html#_ZN9QListView11setViewModeENS_8ViewModeE). It's been like this since before the Nokia days so I can't easily dig out why this is the case.For people ending up here from a search engine, the solution is to put
ui->listWidget->setDragDropMode(QAbstractItemView::DragOnly);
in your widget constructor after the call tosetupUi()
@VRonin
Thank you for this. You may be able to see why I was so confused!I would also say that as per my comment earlier I actually put in the following (after
setupUi()
) to address the issue:ui->listWidget->setAcceptDrops(false);
I don't know how that compares against your
ui->listWidget->setDragDropMode(QAbstractItemView::DragOnly)
, I can only say it is what is working for me in the situation I described. -
@VRonin
Thank you for this. You may be able to see why I was so confused!I would also say that as per my comment earlier I actually put in the following (after
setupUi()
) to address the issue:ui->listWidget->setAcceptDrops(false);
I don't know how that compares against your
ui->listWidget->setDragDropMode(QAbstractItemView::DragOnly)
, I can only say it is what is working for me in the situation I described.