editinlist.py 846 B

1234567891011121314151617181920212223242526272829
  1. # !/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from PyQt5.QtCore import QModelIndex
  4. from PyQt5.QtWidgets import QListWidget
  5. class EditInList(QListWidget):
  6. def __init__(self):
  7. super(EditInList, self).__init__()
  8. self.edited_item = None
  9. def item_clicked(self, modelindex: QModelIndex):
  10. try:
  11. if self.edited_item is not None:
  12. self.closePersistentEditor(self.edited_item)
  13. except:
  14. self.edited_item = self.currentItem()
  15. self.edited_item = self.item(modelindex.row())
  16. self.openPersistentEditor(self.edited_item)
  17. self.editItem(self.edited_item)
  18. def mouseDoubleClickEvent(self, event):
  19. pass
  20. def leaveEvent(self, event):
  21. # close edit
  22. for i in range(self.count()):
  23. self.closePersistentEditor(self.item(i))