editinlist.py 847 字节
Newer Older
1 2 3 4 5
# !/usr/bin/env python
# -*- coding: utf-8 -*-
from PyQt5.QtCore import QModelIndex
from PyQt5.QtWidgets import QListWidget

6 7 8

class EditInList(QListWidget):
    def __init__(self):
9 10 11 12 13 14 15 16 17
        super(EditInList, self).__init__()
        self.edited_item = None

    def item_clicked(self, modelindex: QModelIndex):
        try:
            if self.edited_item is not None:
                self.closePersistentEditor(self.edited_item)
        except:
            self.edited_item = self.currentItem()
18

19 20 21
        self.edited_item = self.item(modelindex.row())
        self.openPersistentEditor(self.edited_item)
        self.editItem(self.edited_item)
22 23

    def mouseDoubleClickEvent(self, event):
24
        pass
25 26 27 28

    def leaveEvent(self, event):
        # close edit
        for i in range(self.count()):
29
            self.closePersistentEditor(self.item(i))