It is the right way but you can remove some lines.
I added moveTop and moveBottom:
Qt Code:
  1. void moveDown(void )
  2. {
  3. int currentIndex = list->currentRow();
  4. QListWidgetItem *currentItem = list->takeItem(currentIndex);
  5. list->insertItem(currentIndex+1, currentItem);
  6. list->setCurrentRow(currentIndex+1);
  7. }
  8.  
  9.  
  10. void moveTop(void )
  11. {
  12. int currentIndex = list->currentRow();
  13. QListWidgetItem *currentItem = list->takeItem(currentIndex);
  14. list->insertItem(0, currentItem);
  15. list->setCurrentRow(0);
  16. }
  17.  
  18.  
  19. void moveBottom(void )
  20. {
  21. int currentIndex = list->currentRow();
  22. QListWidgetItem *currentItem = list->takeItem(currentIndex);
  23. list->insertItem(list->count(), currentItem);
  24. list->setCurrentRow(list->count()-1);
  25. }
  26.  
  27.  
  28. void moveUp(void )
  29. {
  30. int currentIndex = list->currentRow();
  31. QListWidgetItem *currentItem = list->takeItem(currentIndex);
  32. list->insertItem(currentIndex-1, currentItem);
  33. list->setCurrentRow(currentIndex-1);
  34. }
To copy to clipboard, switch view to plain text mode