Exemple #1
0
 def paintEvent(self, event):
     painter = QStylePainter(self)
     painter.setPen(self.palette().color(QPalette.Text))
     # Draw the combobox frame, focus rect, selected etc.
     opt = QStyleOptionComboBox()
     self.initStyleOption(opt)
     opt.currentText = ""  # Don't draw the raw HTML
     painter.drawComplexControl(QStyle.CC_ComboBox, opt)
     # Draw the icon and text
     painter.drawControl(QStyle.CE_ComboBoxLabel, opt)
     # Draw the HTML
     self.label.setText(self.currentText())
     self.label.adjustSize()
     pixmap = QPixmap(self.label.width(), self.label.height())
     pixmap.fill(Qt.transparent)
     self.label.render(pixmap, renderFlags=QWidget.RenderFlags(0))
     rect = QRect(opt.rect)
     y = (rect.height() - self.label.height()) / 2
     rect.setX(self.fontMetrics().width("n"))
     rect.setY(y)
     rect.setHeight(pixmap.height())
     rect.setWidth(pixmap.width())
     painter.drawPixmap(rect, pixmap, pixmap.rect())