PDA

View Full Version : how to move item up and down in QListView



zhanglr
29th July 2008, 23:27
Hi,

In my test application, I have one QListView and two buttons -- Up and Down. When up is clicked I want the current select item in QListView is moved up (E.g. now I have strings 1, 2, 3, 4 in QListView. and I selected 3. after I clicked up. I want the order is 1,3,2,4 and after it, 3 must still be selected.).

Actually, I have two questions about it:
1. How can I move one item up/down?
2. How can I display the selection item even QListView has losted the focus?

Anybody know, what need I do?

Best Regards,
Michael zhang

Valheru
30th July 2008, 19:34
You will have implement removeRows() and insertRows() as well as setData() in your subclassed QAbstractItemModel - I think :p

zhanglr
31st July 2008, 16:35
Hi Valheru,

Looks like I have to do remove item, add item and select item again.:(

BTW, Do you know how to do display the selection item even QListView has losted the focus?

Anyway, thanks a lot for your reply.

Best Regards,
Michael zhang

Valheru
1st August 2008, 15:39
I'm not entirely sure what you mean by that, but I think what you want to take a look at is the QItemSelection class. You can buffer the currently selected items using that class, and then access them via your instance of QItemSelection.