QListWidget elements sorting using drag&drop
I have QListView. I added elements in there using
Question: how to sort elements using drug and drop functionality and after that add some more elements?
I want to add three elements – 1, 2, 3. Then drag first one (1) to the end, so they will be 2, 3, 1. And then I want to add element 4. So after adding fourth element I want 2, 3, 1, 4.
Now I have 1,2,3,4 after adding fourth element.
Is there some functionality to “auto sort elements” after drop? Or where, when and in what method I can get info about where user drop element?
there is a sortingenabled property that you can set to true to do this automatically
It sorts wonderful! But I need sorting in another way.
I need to sort my Model somehow and then View will sort elements in proper way. But how I can get know how user sort elements in View? So I can resort elements in Model and then say View resort View. And it will sort elements in that way as user set.
What do you mean by “I need to sort my Model somehow”. The sort order is always stored and Qt takes care of that for you. When an item is added to the model, does’nt matter whether drag and drop or some other way. Sorting is always retained. Only important part is that your model must know when the data is added.
What do you mean by “I need to sort my Model somehow”.
I have list of my own objects. When I click add button I create object, add it to list and add QListViewItem to QListView with proper text to show user that he add element to list.
All elements have their own place in my list and in QListView. When user sort them in UI I want to know which element now on what position.
User drag first element to the end and now it isn’t on first place. Now it at the end of list. But I can see it only in UI. I don’t know how to get this info in code.