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 import logging
29 logger = logging.getLogger('camelot.view.controls.delegates.comboboxdelegate')
30
31 from customdelegate import CustomDelegate, DocumentationMetaclass
32 from PyQt4 import QtGui, QtCore
33 from PyQt4.QtGui import QComboBox, QItemDelegate
34 from PyQt4.QtCore import QVariant, QString, Qt
35
36 from camelot.view.model_thread import post
37 from camelot.view.controls import editors
38 from camelot.core.utils import variant_to_pyobject
39 from camelot.view.proxy import ValueLoading
40
63 post(create_choices_getter(index.model(), index.row()),
64 editor.set_choices)
65 else:
66 editor.set_choices(self.choices)
67
68 - def paint(self, painter, option, index):
69 painter.save()
70 self.drawBackground(painter, option, index)
71 value = variant_to_pyobject(index.data(Qt.DisplayRole))
72 if value in (None, ValueLoading):
73 value = ''
74 c = index.model().data(index, Qt.BackgroundRole)
75
76
77 if c.type() == QVariant.Invalid:
78 background_color = QtGui.QBrush()
79 else:
80 background_color = QtGui.QColor(c)
81
82 rect = option.rect
83 rect = QtCore.QRect(rect.left() + 3,
84 rect.top() + 6,
85 rect.width() - 5,
86 rect.height())
87
88 if (option.state & QtGui.QStyle.State_Selected):
89 painter.fillRect(option.rect, option.palette.highlight())
90 fontColor = QtGui.QColor()
91 if self.editable:
92 Color = option.palette.highlightedText().color()
93 fontColor.setRgb(Color.red(), Color.green(), Color.blue())
94 else:
95 fontColor.setRgb(130, 130, 130)
96 else:
97 if self.editable:
98 painter.fillRect(option.rect, background_color)
99 fontColor = QtGui.QColor()
100 fontColor.setRgb(0, 0, 0)
101 else:
102 painter.fillRect(option.rect, option.palette.window())
103 fontColor = QtGui.QColor()
104 fontColor.setRgb(130, 130, 130)
105
106 painter.setPen(fontColor.toRgb())
107 rect = QtCore.QRect(option.rect.left()+2,
108 option.rect.top(),
109 option.rect.width()-4,
110 option.rect.height())
111 painter.drawText(rect.x(),
112 rect.y(),
113 rect.width(),
114 rect.height(),
115 Qt.AlignVCenter | Qt.AlignLeft,
116 unicode(value))
117 painter.restore()
118