Delegate drawing elements to popup menu:
class LineStyleDelegate(QtGui.QItemDelegate): def __init__(self, object, parent = None): QtGui.QItemDelegate.__init__(self, parent) def paint(self, painter, option, index): data = index.model().data(index, QtCore.Qt.UserRole) if data.isValid() and data.toPyObject() is not None: data = data.toPyObject() painter.save() rect = option.rect rect.adjust(+5, 0, -5, 0) pen = QtGui.QPen() pen.setColor(QtCore.Qt.black) pen.setWidth(3) pen.setStyle(data) painter.setPen(pen) middle = (rect.bottom() + rect.top()) / 2 painter.drawLine(rect.left(), middle, rect.right(), middle) painter.restore() else: QtGui.QItemDelegate.paint(self, painter, option, index) painter.drawLine(rect.left(), middle, rect.right(), middle) painter.restore() else: QtGui.QItemDelegate.paint(self, painter, option, index)
paintEvent to draw the current item in combo. You can, of course, draw it by hand, but there is an easy way to control the list control yourself (if you want the arrow or smth in the current one):
def paintEvent(self, e): data = self.itemData(self.currentIndex(), QtCore.Qt.UserRole) if data.isValid() and data.toPyObject() is not None: data = data.toPyObject() p = QtGui.QStylePainter(self) p.setPen(self.palette().color(QtGui.QPalette.Text)) opt = QtGui.QStyleOptionComboBox() self.initStyleOption(opt) p.drawComplexControl(QtGui.QStyle.CC_ComboBox, opt) painter = QtGui.QPainter(self) painter.save() rect = p.style().subElementRect(QtGui.QStyle.SE_ComboBoxFocusRect, opt, self) rect.adjust(+5, 0, -5, 0) pen = QtGui.QPen() pen.setColor(QtCore.Qt.black) pen.setWidth(3) pen.setStyle(data) painter.setPen(pen) middle = (rect.bottom() + rect.top()) / 2 painter.drawLine(rect.left(), middle, rect.right(), middle) painter.restore() else: QtGui.QComboBox.paintEvent(self, e)