Esempio n. 1
0
class ItemDelegate(QStyledItemDelegate):

    edited = pyqtSignal(object)

    def __init__(self, all_authors, parent):
        QStyledItemDelegate.__init__(self, parent)
        self.all_authors = all_authors

    def sizeHint(self, *args):
        return QStyledItemDelegate.sizeHint(self, *args) + QSize(0, 15)

    def setEditorData(self, editor, index):
        name = unicode_type(index.data(Qt.DisplayRole) or '')
        editor.setText(name)
        editor.lineEdit().selectAll()

    def setModelData(self, editor, model, index):
        authors = string_to_authors(unicode_type(editor.text()))
        model.setData(index, authors[0])
        self.edited.emit(index.row())

    def createEditor(self, parent, option, index):
        self.ed = EditWithComplete(parent)
        self.ed.setFocusPolicy(Qt.StrongFocus)
        init_line_edit(self.ed, self.all_authors)
        return self.ed
Esempio n. 2
0
class ItemDelegate(QStyledItemDelegate):

    edited = pyqtSignal(object)

    def __init__(self, all_authors, parent):
        QStyledItemDelegate.__init__(self, parent)
        self.all_authors = all_authors

    def sizeHint(self, *args):
        return QStyledItemDelegate.sizeHint(self, *args) + QSize(0, 15)

    def setEditorData(self, editor, index):
        name = unicode_type(index.data(Qt.DisplayRole) or '')
        editor.setText(name)
        editor.lineEdit().selectAll()

    def setModelData(self, editor, model, index):
        authors = string_to_authors(unicode_type(editor.text()))
        model.setData(index, authors[0])
        self.edited.emit(index.row())

    def createEditor(self, parent, option, index):
        self.ed = EditWithComplete(parent)
        self.ed.setFocusPolicy(Qt.StrongFocus)
        init_line_edit(self.ed, self.all_authors)
        return self.ed