editinlist.py 958 B

12345678910111213141516171819202122232425262728293031
  1. import sys, time
  2. from PyQt5 import QtWidgets
  3. from PyQt5.QtGui import *
  4. from PyQt5.QtCore import *
  5. from PyQt5.QtWidgets import *
  6. class EditInList(QListWidget):
  7. def __init__(self):
  8. super(EditInList,self).__init__()
  9. # click to edit
  10. self.clicked.connect(self.item_clicked)
  11. def item_clicked(self, modelindex: QModelIndex) -> None:
  12. self.edited_item = self.currentItem()
  13. self.closePersistentEditor(self.edited_item)
  14. item = self.item(modelindex.row())
  15. # time.sleep(0.2)
  16. self.edited_item = item
  17. self.openPersistentEditor(item)
  18. # time.sleep(0.2)
  19. self.editItem(item)
  20. def mouseDoubleClickEvent(self, event):
  21. # close edit
  22. for i in range(self.count()):
  23. self.closePersistentEditor(self.item(i))
  24. def leaveEvent(self, event):
  25. # close edit
  26. for i in range(self.count()):
  27. self.closePersistentEditor(self.item(i))