-
Notifications
You must be signed in to change notification settings - Fork 2
/
delegateComboBox.py
56 lines (45 loc) · 2.06 KB
/
delegateComboBox.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
/***************************************************************************
Heroquest's Legends Solo by Mandor the Druid
-------------------
begin : 2021-01-02
copyright : (C) 2021 by Luca Mandolesi
email : mandoluca at gmail.com
version : 0.91 ALPHA
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox, QItemDelegate, QComboBox
class ComboBoxDelegate(QItemDelegate):
values = ""
editable = ""
def __init__(self, parent=None):
QItemDelegate.__init__(self, parent)
def def_values(self, values):
self.values = values
def def_editable(self, editable):
self.editable = editable
def createEditor(self, parent, option, index):
editor = QComboBox(parent)
editor.addItems(self.values)
editor.setEditable(eval(self.editable))
return editor
def setEditorData(self, editor, index):
text = index.model().data(index, Qt.DisplayRole) # .String()
i = editor.findText(text)
if i == -1:
i = 0
editor.setCurrentIndex(i)
def setModelData(self, editor, model, index):
# model.setData(index, QtCore.QVariant(editor.currentText() ))
model.setData(index, editor.currentText())