editinlist.py 958 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
import sys, time
from PyQt5 import QtWidgets
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *

class EditInList(QListWidget):
    def __init__(self):
        super(EditInList,self).__init__()
        # click to edit
        self.clicked.connect(self.item_clicked)  

    def item_clicked(self, modelindex: QModelIndex) -> None:
        self.edited_item = self.currentItem()
        self.closePersistentEditor(self.edited_item)
        item = self.item(modelindex.row())
        # time.sleep(0.2)
        self.edited_item = item
        self.openPersistentEditor(item)
        # time.sleep(0.2)
        self.editItem(item)

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

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