def createEditor(self, parent: QWidget, option: QStyleOptionViewItem, index: QModelIndex):
editor = QComboBox(parent)
if sys.platform == "win32":
# Ensure text entries are visible with windows combo boxes
editor.setMinimumHeight(self.sizeHint(option, index).height() + 10)
editor.addItems(self.items)
if self.is_editable:
editor.setEditable(True)
editor.setInsertPolicy(QComboBox.NoInsert)
if self.current_edit_text:
editor.setEditText(self.current_edit_text)
if self.colors:
img = QImage(16, 16, QImage.Format_RGB32)
painter = QPainter(img)
painter.fillRect(img.rect(), Qt.black)
rect = img.rect().adjusted(1, 1, -1, -1)
for i, item in enumerate(self.items):
color = self.colors[i]
painter.fillRect(rect, QColor(color.red(), color.green(), color.blue(), 255))
editor.setItemData(i, QPixmap.fromImage(img), Qt.DecorationRole)
del painter
editor.currentIndexChanged.connect(self.currentIndexChanged)
editor.editTextChanged.connect(self.on_edit_text_changed)
return editor
评论列表
文章目录