QListWidget dragDropMode = InternalMove except the 2 first
-
Hello every one,
In a QListWidget I've set dragDropMode = InternalMove so that the user can reorder elements in list.
This works well however I would like to prevent the first 2 elements to be moved, they must always stay the two first, we cannot move them and we cannot place any element before/between them, reordering is allowed only within range (3, ... infinite)A solution would be to subscribe to the @dropEvent ( QDropEvent * event )@ and cancel the drag&drop action if it's not allowed but I don't know if this is possible. Something like event->acceptThisDrop(false) would be perfect haha!
Something even more userfriendly would be to make it impossible to start any drag action with the two first elements nor terminate any drop action within the 1st and 2nd position.
Any idea to do this as simple as possible?
Thanks -
Hi,
What about setting the item flags of the two first elements to Qt::NoItemFlags ?
-
Hi all and thanks :)
I forgot to mention that one element at a time can be selected in this list, including the two first. I must forbid only drag&drop-ing these two but they must be clickable.
@ckakman well, that would be a bit annoying to synchronize both list since the user can select one element
@SGaist your solution disables the item completely, I cannot click them anymore and they are grey.
-
Then maybe reimplement the drop event to "freeze" the portion of the widget where they reside
-
[quote author="myoan" date="1421401499"]Hi all and thanks :)
I forgot to mention that one element at a time can be selected in this list, including the two first. I must forbid only drag&drop-ing these two but they must be clickable.
ckakman well, that would be a bit annoying to synchronize both list since the user can select one element
[/quote]
I'd say just deselect items in one list when an item in the other list is selected. In a slot connected to itemActivated():
@
foreach( QListWidgetItem *item, ui->otherList->selectedItems() )
item->setSelected(false);
@Repeat this for the other table as well. 4 lines of code in total in 2 slots plus connecting the signals.